FeaturePyton. What happens when a user opens a document?
Is this sequence described somewhere?
I noticed that when opening a FeaturePython document, properties are assigned, but for some reason _init_() is not called. What then should initialize the object?
FeaturePyton. What happens when a user opens a document?
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: FeaturePyton. What happens when a user opens a document?
If I understood correctly
When loading, all values are iterated, starting from Proxy value, and the onChanged(self, obj, prop) method is called for each itarated value.
There is a method onDocumentRestored(self, obj), but it starts after iterating through all the values.
https://wiki.freecadweb.org/FeaturePython_methods
After reading this branch as an output, is possible to check the connections between objects when the onChange method invoked.
https://forum.freecadweb.org/viewtopic.php?t=13740
It would be nice to have the OnInit() method for self-initialization. And so that this method is called before iterating over variables. Although it is possible to all without it.
When loading, all values are iterated, starting from Proxy value, and the onChanged(self, obj, prop) method is called for each itarated value.
There is a method onDocumentRestored(self, obj), but it starts after iterating through all the values.
https://wiki.freecadweb.org/FeaturePython_methods
After reading this branch as an output, is possible to check the connections between objects when the onChange method invoked.
https://forum.freecadweb.org/viewtopic.php?t=13740
It would be nice to have the OnInit() method for self-initialization. And so that this method is called before iterating over variables. Although it is possible to all without it.
Re: FeaturePyton. What happens when a user opens a document?
You can deactivate the onChanged method during document loading with :
Then I think you can use onDocumentRestored as your an init method, called once all the properties of the object are fully restored.
Code: Select all
def onChanged( self, fp, prop):
if "Restore" in fp.State:
return
...
Re: FeaturePyton. What happens when a user opens a document?
I use construction like this:
Code: Select all
def onChanged(self, obj, prop):
App.Console.PrintMessage("Change property: " + str(prop) + "\n")
val = obj.getPropertyByName(prop)
if prop == "ObjectData":
featureobj = self.createObjectIfItNotExists()
featureobj.data = val
...
Re: FeaturePyton. What happens when a user opens a document?
I am sorry, but I lack more context and info to help further.
What I understand is that you have a FeaturePython object (obj) that creates a FeatureObject (featureobj) and transfers the data of the ObjectData property (what type of property is it ?) to it.
Without more context, this looks quite convoluted.
What I understand is that you have a FeaturePython object (obj) that creates a FeatureObject (featureobj) and transfers the data of the ObjectData property (what type of property is it ?) to it.
Without more context, this looks quite convoluted.