Hi,
I tried to use a PropertyEnum in a part python feature (for ex. try to draw a Draft rectangle or wire, in its view properties there are "Fill Style" and "Line Style" properties), but when you save the document and open it again, the contents of that property is lost.
Is there something special to do?
Cheers
Y
PropertyEnum in Python feature
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: PropertyEnum in Python feature
This was a bug which is fixed in revision 3420.
When assigning custom enumeration values from within Python we didn't store them to the XML file. This should now work.Is there something special to do?
Re: PropertyEnum in Python feature
Thanks for the fix Werner, it works OK!
Re: PropertyEnum in Python feature
Hm I think I spoke too soon...
There is a problem but I cannot find what's going wrong...
Try making 1 or 2 draft rectangles, and save the file? It crashes on reopening it...
The culprits are 2 PropertyEnums of those rectangles, (FillStyle and LineStyle)...
But I cannot figure out what's going on, I tried removing one of the properties, then it works,
or changing the name of FillStyle for another one (surprisingly it then works if there is only ONE rectangle)
Those 2 properties are of the viewobject, not the object...
Using your example in TemplatePyMod works, but it has no view provider, I suppose the problem is there?
Can you have a look?
Thanks
Y
There is a problem but I cannot find what's going wrong...
Try making 1 or 2 draft rectangles, and save the file? It crashes on reopening it...
The culprits are 2 PropertyEnums of those rectangles, (FillStyle and LineStyle)...
But I cannot figure out what's going on, I tried removing one of the properties, then it works,
or changing the name of FillStyle for another one (surprisingly it then works if there is only ONE rectangle)
Those 2 properties are of the viewobject, not the object...
Using your example in TemplatePyMod works, but it has no view provider, I suppose the problem is there?
Can you have a look?
Thanks
Y
Re: PropertyEnum in Python feature
Here is a piece of code that reproduces the problem. I just adapted your EnumTest example to give it a view provider.
The object gets created correctly, but if you save the doc freecad crashes on reopening the file
The object gets created correctly, but if you save the doc freecad crashes on reopening the file
Code: Select all
class EnumTest:
def __init__(self, obj):
''' Add enum properties '''
obj.addProperty("App::PropertyEnumeration","Enum","","Enumeration").Enum=["One","Two","Three"]
obj.addProperty("App::PropertyEnumeration","Enum2","","Enumeration2").Enum2=["One","Two","Three"]
obj.Proxy = self
def execute(self, fp):
return
class ViewProviderEnumTest:
def __init__(self, obj):
''' Set this object to the proxy object of the actual view provider '''
obj.addProperty("App::PropertyEnumeration","Enum3","","Enumeration3").Enum3=["One","Two","Three"]
obj.addProperty("App::PropertyEnumeration","Enum4","","Enumeration4").Enum4=["One","Two","Three"]
obj.Proxy = self
def updateData(self, fp, prop):
print "prop updated:",prop
def __getstate__(self):
return None
def __setstate__(self,state):
return None
def makeEnumTest():
a=FreeCAD.ActiveDocument.addObject("Part::FeaturePython","Enum")
EnumTest(a)
ViewProviderEnumTest(a.ViewObject)
Re: PropertyEnum in Python feature
This was a critical bug in the XML reader class which didn't reset attributes of an element after reading them in. Just a wonder that this bug didn't appear earlier... This is fixed in revision 3427.
Re: PropertyEnum in Python feature
Okay, that solved it! Thanks Werner!