Inheriting sketch feature.

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Inheriting sketch feature.

Post by TheMarkster »

This is highly experimental. Save your work and save often.

Put DuplicateManager.FCMacro and duplicatemanager.py into your macro folder. Only run the .FCMacro file, not the py file. It is only there to be imported by the macro file.

Duplicate your objects first.

Then select them all and run the macro. It creates a DuplicateManager object that uses a document observer to see when any of the objects it is managing has left editing mode in a task dialog. (Changing a property with the property editor in the property view will not trigger anything, must be done within a task dialog editor, such as the sketch editor or when double clicking a primitive to bring up the editor for that object.) When this is detected the object that was modified is duplicated in all of the managed objects. In other words, change one and the rest all change, no matter which of them is changed. These are like clones on steroids. 2-way clones. Just remember if you change a property in the property editor the change isn't propagated, but if you anything is changed in the task dialog editor, then everything gets updated in all the duplicates.

DuplicateManager can be be disabled by setting its Enabled property to False. Deleting it also causes it to remove the document observer.

Edit: I forgot to mention, the Placement property is not duplicated and none of the properties associated with attachments are duplicated, such as MapMode, etc.
Attachments
DuplicateManager.FCMacro
(467 Bytes) Downloaded 25 times
duplicatemanager.py
(5.77 KiB) Downloaded 22 times
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Inheriting sketch feature.

Post by drmacro »

Just curious, why use .FCMacro to load the .py?

:?:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Inheriting sketch feature.

Post by drmacro »

TheMarkster wrote: Mon Oct 18, 2021 4:28 am
Just curious, why use .FCMacro to load the .py?
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Inheriting sketch feature.

Post by TheMarkster »

drmacro wrote: Mon Oct 18, 2021 3:55 pm
Just curious, why use .FCMacro to load the .py?
If you put the class definitions in the .FCmacro file it works fine, but if you save the document, and restart FreeCAD, then when you open the document the objects are broken. But if you import from .py files when FreeCAD sees the object in the document it knows where to get the class definitions. If there is a way to make it all work from the single .FCMacro file I don't know what it is. There might be a way. I just don't know what it is.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Inheriting sketch feature.

Post by TheMarkster »

Looks like the DuplicateManager is sort of broken on reload anyway. You have to toggle Enabled off and back on to get the document observer installed again.

Properties bound by Expressions retain those bindings after the duplication manager does its thing, so expressions override the duplication process. For example, if you have 3 cylinders being managed and you have the height property of one of them set as an expression when you change the height of another of the cylinders the one with the expression retains its current height. Actually, its height is changed by the duplicate manager, but then resets itself because of the expression.

Weird side effect: the labels can change, but I think the names remain the same. So if you use an Expression referencing one of the duplicates reference the name not the label.

Some objects don't have the task dialog editors, but just opening transform dialog and closing without moving also triggers the duplicate manager to do its thing. The one that is edited/transformed is the master copy. Anything that opens a task dialog on the object, such the set colors dialog will also trigger the manager whether changes are made or not. The observer is watching for the resetEdit() signal.

You can remove an object from the set by editing the DuplicatesNNN property (a string property containing the name of the object). Or you can add more by creating a new string property named DuplicatesNNN where NNN is the next number. I should have made this a single stringlist property, but I was thinking at the time having separate properties would be a way to determine which object changed. To add a new property, right click on a property -> show all, right click again, add new property -> string -> Duplicates5 for example if the last Duplicates property is Duplicates4.

All Duplicates should be the same type of object, but this isn't tested for. If you try to mix different object types do so at your own risk. Come to think of it, everything is at your own risk anyway.

What's the use of this? Why not just use clones? I don't know that there is one. Give users a tool and they will come up with creative ways to use it that you never imagined.
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Inheriting sketch feature.

Post by drmacro »

TheMarkster wrote: Mon Oct 18, 2021 4:20 pm
drmacro wrote: Mon Oct 18, 2021 3:55 pm
Just curious, why use .FCMacro to load the .py?
If you put the class definitions in the .FCmacro file it works fine, but if you save the document, and restart FreeCAD, then when you open the document the objects are broken. But if you import from .py files when FreeCAD sees the object in the document it knows where to get the class definitions. If there is a way to make it all work from the single .FCMacro file I don't know what it is. There might be a way. I just don't know what it is.
I saved the .FCMacro as .py and it seems to work as described. :?:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Inheriting sketch feature.

Post by drmacro »

TheMarkster wrote: Mon Oct 18, 2021 4:55 pm Looks like the DuplicateManager is sort of broken on reload anyway. You have to toggle Enabled off and back on to get the document observer installed again.
...
I see that.

I've haven't ventured into observers as yet...
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Inheriting sketch feature.

Post by TheMarkster »

drmacro wrote: Mon Oct 18, 2021 4:59 pm
I saved the .FCMacro as .py and it seems to work as described. :?:
Yes, the .FCMacro extension is not necessary and probably should never have been introduced. It just makes working with IDE's more of a headache because they don't know these are to be interpreted as .py files and as far as I know you can't import from a .FCMacro file. But this doesn't change the 2 file requirement.
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Inheriting sketch feature.

Post by TheMarkster »

I initially wanted to use a different observer (slotChangedObject) but it wasn't working where checking for resetEdit() was working, so I abandoned it and just used the resetEdit observer. I don't know if it's a bug in FreeCAD or just (more likely) something I was doing wrong. But being able to tweak via the properties editor a single duplicate without changing the others could be an advantage, so I went this route for that reason, too.
drmacro
Veteran
Posts: 8868
Joined: Sun Mar 02, 2014 4:35 pm

Re: Inheriting sketch feature.

Post by drmacro »

TheMarkster wrote: Mon Oct 18, 2021 5:08 pm
Yes, the .FCMacro extension is not necessary and probably should never have been introduced.
Agreed.
... But this doesn't change the 2 file requirement.
Agreed. When I'm trying to figure out a starting point, I'll use the macro record, it of course creates a .FCMacro. I immediately rename it to .py and proceed with whatever I'm up to. ;)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Post Reply