Code: Select all
from FreeCAD import Units
from femobjects import base_fempythonobject
class MyNewObject(base_fempythonobject.BaseFemPythonObject):
Type = "Fem::MyNewObject"
def __init__(self, obj):
super(MyNewObject, self).__init__(obj)
obj.addProperty(
"App::PropertyQuantity",
"MyNewProperty",
"MyPropertyGroup",
"Set my new PropertyQuantity"
)
newobj = App.ActiveDocument.addObject("Fem::ConstraintPython", "FunnyObject")
MyNewObject(newobj)
newobj.MyNewProperty = Units.Quantity("1 s^4*A^2 / (m^3*kg)")
newobj.MyNewProperty = Units.Quantity("1 mm")
Code: Select all
>>>
>>> from FreeCAD import Units
>>> from femobjects import base_fempythonobject
>>>
>>> class MyNewObject(base_fempythonobject.BaseFemPythonObject):
...
... Type = "Fem::MyNewObject"
...
... def __init__(self, obj):
... super(MyNewObject, self).__init__(obj)
... obj.addProperty(
... "App::PropertyQuantity",
... "MyNewProperty",
... "MyPropertyGroup",
... "Set my new PropertyQuantity"
... )
...
>>>
>>>
>>> newobj = App.ActiveDocument.addObject("Fem::ConstraintPython", "FunnyObject")
>>> MyNewObject(newobj)
<__main__.MyNewObject object at 0x7f6e3d351b70>
>>> newobj.MyNewProperty = Units.Quantity("1 s^4*A^2 / (m^3*kg)")
Traceback (most recent call last):
File "<input>", line 1, in <module>
ArithmeticError: Not matching Unit!
>>> newobj.MyNewProperty = Units.Quantity("1 mm")
Traceback (most recent call last):
File "<input>", line 1, in <module>
ArithmeticError: Not matching Unit!
>>>