Python4Capella PVMT Problem with get_or_apply_property_value_group

I have just started using Python4Capella, and when arrived to pvmt access, I had a couple of problems. I read the topics:

and the github issue https://github.com/labs4capella/python4capella/issues/168

Following the last P4C release, I started to use the new methods for PVMT class and I had a problem with
@staticmethod
def get_or_apply_property_value_group(elem: CapellaElement, propertyValuePackageName: str, propertyValueGroupName: str) → PropertyValue:

Running it as it is I receive this error message:

org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File “workspace://UserScripts/user_scripts/main2.py”, line 54, in
File “workspace://Python4Capella/simplified_api/pvmt.py”, line 162, in get_or_apply_property_value_group
Extension to standard InteractiveConsole so we can handle and capture
File “workspace://Python4Capella/simplified_api/capella.py”, line 603, in set_value
File “C:\Users\a.mastropietro\Softwares\Capella\capella-6.1.0.202303291413-win32-win32-x86_64\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py”, line 1313, in call
args_command, temp_args = self._build_args(*args)
File “C:\Users\a.mastropietro\Softwares\Capella\capella-6.1.0.202303291413-win32-win32-x86_64\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py”, line 1283, in _build_args
[get_command_part(arg, self.pool) for arg in new_args])
File “C:\Users\a.mastropietro\Softwares\Capella\capella-6.1.0.202303291413-win32-win32-x86_64\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py”, line 1283, in
[get_command_part(arg, self.pool) for arg in new_args])
File “C:\Users\a.mastropietro\Softwares\Capella\capella-6.1.0.202303291413-win32-win32-x86_64\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\protocol.py”, line 298, in get_command_part
command_part = REFERENCE_TYPE + parameter._get_object_id()
AttributeError: ‘EnumerationPropertyLiteral’ object has no attribute ‘_get_object_id’

but commenting out line 162 pv_to_apply.set_value(pv.get_value()) this method seems to work correctly, creating the PVMT group as defined in the add-on. Then changing the values manually, everything works.

Is this a good solution or should 162 line do something I have not understood?

Thanks for the help!

1 Like

I think you just found a bug. At line 162 we set the value of the applied property value. Most of the time it’s a primitive type and it can be directly passed to the underlying Java code. But here the value is a EnumerationPropertyLiteral (an instance of the Python class defined in capella.py) which is a Python object. in this case we need to pass the corresponding Java Object:

pv_to_apply.get_java_object().setType(pv.get_java_object().getType())

Which is literally the next line… That’s a stupid bug I made, the fix:

                if pv.get_java_object().eClass().getName() == "EnumerationPropertyValue":
                    pv_to_apply.get_java_object().setType(pv.get_java_object().getType())
                else:
                    pv_to_apply.set_value(pv.get_value())

I opened the following issue:

Until the next release, you can patch your local pvmt.py.

2 Likes