Hello, I have the following problem. I want to mark the document so that it does not recalculate when there are changes in the objects, but does so by means of a python instruction, but recalculates some objects that I want, not all of them. For example, if I made changes to a cube and a cylinder and I only want the cylinder recalculated, not the cube. Then later, you may want to recalculate the whole document.
I need to know how to do all this with the python instructions.
Thanks
Recalculate some objects through python
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- dcapeletti
- Posts: 504
- Joined: Wed Jul 23, 2014 2:27 pm
Re: Recalculate some objects through python
I cannot imagine how this should work.
Each object (cube, cylinder etc.) has an internal method onChanged, which is executed if you recalculate the document. onChanged is called from "inside" of FC.
Each object (cube, cylinder etc.) has an internal method onChanged, which is executed if you recalculate the document. onChanged is called from "inside" of FC.
Re: Recalculate some objects through python
To disable global recompute at document level :
Set to 'False' to enable again
Then for each object you can call :
If you want a recursive recompute (ie. children are recomputed) :
Code: Select all
App.ActiveDocument.RecomputesFrozen = True
Then for each object you can call :
Code: Select all
OBJECT.recompute()
Code: Select all
OBJECT.recompute(True)
Re: Recalculate some objects through python
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
- dcapeletti
- Posts: 504
- Joined: Wed Jul 23, 2014 2:27 pm
Re: Recalculate some objects through python
Thank you all for your help.
-
- Posts: 54
- Joined: Sat Dec 19, 2020 11:55 pm
Re: Recalculate some objects through python
I think that onChanged is meant to update the object's properties (e.g. if you have a property which appears only when another is set to True, or your properties are linked in some other way (please don't do conditional properties if you can avoid doing so, it prevents other tools from iterating over the properties to display them in an alternate interface, e.g. a nodal interface)). I've seen it used as a hack to go from a list of strings to a list of App::PropertyLink: when the list of strings was updated, it was copied to the App::PropertyLink property to get a real link to the objec, IIUC the code correctly (in the Lattice2 workbench by DeepSOIC).
In order to do something when the object gets recomputed, the execute() method should be implemented instead