Page 1 of 1
[Solved] Skip excution for some properties
Posted: Mon Oct 16, 2017 7:13 am
by jaisejames
I having some code like below. I want to skip obj execution on change Property like "NomenclatureofWall" because it is holding some text for identification, example "back wall", "Garden side wall" etc. Because setting this text cause entire model unresponsive some seconds.
Code: Select all
class Wall:
def __init__(self,obj):
obj.Proxy = self
obj.addProperty("App::PropertyFloat","LengthofWall")
obj.addProperty("App::PropertyString","NomenclatureofWall")
Re: Skip excution for some properties
Posted: Mon Oct 16, 2017 7:28 am
by microelly2
You can set a flag when a property is changed you want to ignore it during execute
Code: Select all
def onChanged(self, fp, prop):
print ("onChanged",prop)
if prop=="Size" or prop in ["NomenclatureofWall","n2","e1","e2","e3"]:
set a flag ....
Re: Skip excution for some properties
Posted: Mon Oct 16, 2017 7:37 am
by wmayer
When adding a property you can mark it as output property. This way it won't mark the feature as touched when changing it.
Code: Select all
obj.addProperty("App::PropertyString","NomenclatureofWall","","",8)
Here you can find the different property types:
https://github.com/FreeCAD/FreeCAD/blob ... iner.h#L42
Re: Skip excution for some properties
Posted: Mon Oct 16, 2017 8:47 am
by jaisejames
Thank you all for very quick support.
One for help. I created PropertyLinkList like below code
Code: Select all
for i, sub in enumerate(obj.Objects):
obj.addProperty('App::PropertyLinkList', "DoorList%d" % i, .....)
obj.addProperty('App::PropertyFloatList', "DoorPosition%d" % i, .....)
based on
https://forum.freecadweb.org/viewtopic.php?f=22&t=23735
Onchange, newly created items/list is coming in bottom of property editor. Now I click another object, then click on object property will sort it properly. Any method to refresh property editor is available without clicking.
Re: [Solved] Skip excution for some properties
Posted: Mon Oct 23, 2017 7:56 pm
by yorik
wmayer wrote: ↑Mon Oct 16, 2017 7:37 amWhen adding a property you can mark it as output property. This way it won't mark the feature as touched when changing it.
One more for my "things I still didn't know in FreeCAD" list
Re: Skip excution for some properties
Posted: Wed Jun 09, 2021 5:54 pm
by paullee
Sorry bringing this up so late again.
Searching around and found this, wondering what is the difference between 8 and 16?
Thanks
Code: Select all
Prop_Output = 8, /*!< Modified property doesn't touch its parent container */
Prop_NoRecompute = 16,/*!< Modified property doesn't touch its container for recompute */
Re: [Solved] Skip excution for some properties
Posted: Mon Jun 14, 2021 1:27 pm
by wmayer
Here is the reasoning for adding the new enum value:
https://github.com/FreeCAD/FreeCAD/comm ... 2da2524be3
The main problem was the ambiguous meaning of the Prop_Output. On the one hand it was used to control if a property marks a container (i.e. a feature) as touched when it has changed and on the other hand it was used to control if a feature needs to be recomputed.
In order to make this working properly every sub-class of DocumentObject need a consistent implementation of mustExecute(). But because many classes lack of it or the implementation was wrong it led to situations where a touched feature wasn't recomputed when it should have been or the other way where a feature was recomputed too often when it wasn't needed. The issue was discussed in several forum topics but I don't have a link to them any more.
With Prop_NoRecompute things have been clarified and feature sub-classes don't have to provide the mustExecute() method any more.
So, if the goal is that a feature can be marked as touched but shouldn't be recomputed then use: Prop_NoRecompute
If you don't even want that a changed property marks the feature as touched then use: Prop_Output
Hint: The Prop_Output is stronger than Prop_NoRecompute. So, if Prop_Output is set the property won't mark the feature for a recompute either.
Re: [Solved] Skip excution for some properties
Posted: Fri Jul 02, 2021 7:41 pm
by paullee
wmayer wrote: ↑Mon Jun 14, 2021 1:27 pm
So, if the goal is that a feature can be marked as touched but shouldn't be recomputed then use: Prop_NoRecompute
If you don't even want that a changed property marks the feature as touched then use: Prop_Output
Hint: The Prop_Output is stronger than Prop_NoRecompute. So, if Prop_Output is set the property won't mark the feature for a recompute either.
Thanks for the detailed explanation. Start to understand after reading and thinking about the usecases for a while
Maybe this should be included in wiki, e.g. the Scripted Object, where there is a link to this thread in fact?
Re: Skip excution for some properties
Posted: Sun Jul 11, 2021 11:37 am
by paullee
wmayer wrote: ↑Mon Oct 16, 2017 7:37 am
Code: Select all
obj.addProperty("App::PropertyString","NomenclatureofWall","","",8)
Sorry bringing up this again, found issue when use this with Sketcher::SketchObjectPython :
- When the object is created, no problem the property is shown with 'output' and 'hidden with below code
- But when the file is saved and re-opened, the property become 'read-only'
- " <class 'AttributeError'>: Object attribute 'MasterSketchSubelementIndex' is read-only" when code want to update this
- Just find a Feature Python object (like ArchEquipment) has similar issue, [edit] if similar attribute is added [/edit], but code CAN update the attribute, THOUGH IT IS SIMILARLY READ ONLY
Any idea? Thanks
Code: Select all
class ArchSketch:
def __init__(self, fp):
self.setProperties(fp)
def setProperties(self, fp):
prop = fp.PropertiesList
if "MasterSketchSubelementIndex" not in prop:
fp.addProperty("App::PropertyInteger","MasterSketchSubelementIndex","Test","Test", 4+8)
archSketch=App.ActiveDocument.addObject("Sketcher::SketchObjectPython",'ArchSketch_NAME')
Upon Creation
- WhatsApp Image 2021-07-11 at 19.18.29.jpeg (258.16 KiB) Viewed 1838 times
Upon DocumentRestored
- WhatsApp Image 2021-07-11 at 19.16.26.jpeg (294.33 KiB) Viewed 1838 times
EDIT:
AppImage running on Fedora 3 -
OS: Fedora 31 (Workstation Edition) (GNOME/gnome)
Word size of FreeCAD: 64-bit
Version: 0.20.25025 (Git)
Build type: Release
Branch: master
Hash: fb8b21ec43dca706a4aa2d63d59a4fb79f050369
Python version: 3.9.4
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.2
Locale: English/United States (en_US)
Re: [Solved] Skip excution for some properties
Posted: Sun Jul 11, 2021 5:39 pm
by paullee
Just find if no 'hidden' is set, it works. But it is shown in the editor and allow user to edit, not 'hidden'.
Code: Select all
fp.addProperty("App::PropertyInteger","MasterSketchSubelementIndex","Test","Test", 4+8)
change to -
fp.addProperty("App::PropertyInteger","MasterSketchSubelementIndex","Test","Test", 8)