[Solved] Skip excution for some properties

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jaisejames
Posts: 384
Joined: Sat Sep 24, 2016 6:51 am

[Solved] Skip excution for some properties

Post 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")
   
Last edited by jaisejames on Mon Oct 23, 2017 8:34 am, edited 1 time in total.
User avatar
microelly2
Veteran
Posts: 4688
Joined: Tue Nov 12, 2013 4:06 pm
Contact:

Re: Skip excution for some properties

Post 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 ....

wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Skip excution for some properties

Post 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
jaisejames
Posts: 384
Joined: Sat Sep 24, 2016 6:51 am

Re: Skip excution for some properties

Post 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.
User avatar
yorik
Founder
Posts: 13640
Joined: Tue Feb 17, 2009 9:16 pm
Location: Brussels
Contact:

Re: [Solved] Skip excution for some properties

Post 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 :)
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: Skip excution for some properties

Post by paullee »

wmayer wrote: Mon Oct 16, 2017 7:37 am 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
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 */
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [Solved] Skip excution for some properties

Post 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.
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [Solved] Skip excution for some properties

Post 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?
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: Skip excution for some properties

Post 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 :
  1. When the object is created, no problem the property is shown with 'output' and 'hidden with below code
  2. But when the file is saved and re-opened, the property become 'read-only'
  3. " <class 'AttributeError'>: Object attribute 'MasterSketchSubelementIndex' is read-only" when code want to update this
  4. 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')
Test_ ArchSketch_ 39_ Debug-General-Test.fcstd
(18.01 KiB) Downloaded 26 times

Upon Creation
WhatsApp Image 2021-07-11 at 19.18.29.jpeg
WhatsApp Image 2021-07-11 at 19.18.29.jpeg (258.16 KiB) Viewed 1822 times

Upon DocumentRestored
WhatsApp Image 2021-07-11 at 19.16.26.jpeg
WhatsApp Image 2021-07-11 at 19.16.26.jpeg (294.33 KiB) Viewed 1822 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)
paullee
Veteran
Posts: 5098
Joined: Wed May 04, 2016 3:58 pm

Re: [Solved] Skip excution for some properties

Post 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)          
Test_ ArchSketch_ 39r_ Debug-General-Test.fcstd
(18.11 KiB) Downloaded 23 times
Post Reply