Hello,
I have been experimenting with the function (PropertyValue()), and was able to create a BooleanPropertyValue, with this:
PV9=PropertyValue("BooleanPropertyValue")
The problem comes when I try to set its name or value.
__
This problem does not seem to appear with a StringPropertyValue (Default type attributed to a Property value). Indeed if we created a property Value and gave it NO type, such as:
PV8=PropertyValue()
#PV8.set_name("TST_OK")
PV8.set_value("TST_OK")
Well everything works as intended, both of the functions above work. set_name() works okay because the PropertyValue class inherit from the class CapellaElement I believe. And set_value() works, because it is one of the functions of the class PropertyValue.
However, it seems neither of thiese functions would work for a BooleanPropertyValue?
Let’s take a look at the class, click to expand:
PropertyValue Class:
class PropertyValue(CapellaElement):
"""
A generic property with a name and value which can be added to Capella elements
"""
def __init__(self, java_object = None, kind = "StringPropertyValue"):
"""
"""
if java_object is None:
if kind in ["BooleanPropertyValue", "EnumerationPropertyValue", "FloatPropertyValue", "IntegerPropertyValue", "StringPropertyValue" ]:
JavaObject.__init__(self, create_e_object("http://www.polarsys.org/capella/core/core/" + capella_version(), kind))
else:
raise ValueError("kind must be either \"BooleanPropertyValue\", \"EnumerationPropertyValue\", \"FloatPropertyValue\", \"IntegerPropertyValue\", or \"StringPropertyValue\"")
elif isinstance(java_object, PropertyValue):
JavaObject.__init__(self, java_object.get_java_object())
else:
JavaObject.__init__(self, java_object)
def get_kind(self):
"""
"""
return self.java_object.eClass().getName()
def get_value(self):
"""
"""
return self.get_java_object().getValue()
def set_value(self, value):
"""
"""
self.get_java_object().setValue(value)
def get_valued_elements(self):
"""
"""
return create_e_list(self.get_java_object().getValuedElements(), CapellaElement)
def get_type(self):
"""
"""
value = self.get_java_object().getType()
if value is None:
return value
else:
e_object_class = getattr(sys.modules["__main__"], "EObject")
specific_cls = e_object_class.get_class(value)
return specific_cls(value)
As I understand it, the default “kind” is StringPropertyValue.
Whenever I try to define another kind such as a Boolean (See the code at the beginning of this post (PV9=…), the functions set_name and set_value seems to not work maybe?
Maybe I am doing something wrong. Please enlighten me if I missed anything.
Thank you.
Edit: To be clear, here is the message error I get:
PV9=PropertyValue("BooleanPropertyValue")
print(PV9)
print(PV9.java_object)
#print(PV9.java_object.eClass())
#print(PV9.java_object.eClass().getName()) # does not work (ERROR 1)
a=PV9.get_kind()
#print(a)
PV9.set_value(TRUE)#("TEST") #Error message (ERROR 2)
Error 1 is as follows:
File “L/Python4Capella/sample_scripts/NewScript5_2306_ changedAbit.py”, line …, in
AttributeError: ‘str’ object has no attribute ‘eClass’
Error 2 is like this:
File “L/Python4Capella/sample_scripts/NewScript5_2306_ changedAbit.py”, line …, in
File “L/Python4Capella/simplified_api/capella.py”, line 478, in set_value
AttributeError: ‘str’ object has no attribute ‘setValue’
(PV9.set_value(True) and PV9.set_value(true), do not work neither)