Unable to print the name of a physical component

Hi,

I have the following code where I’m trying to write the name of a physical component :

print(pc)

The result show that a physical component that has a name :

org.polarsys.capella.core.data.pa.impl.PhysicalComponentImpl@5c0d6858 (id: da5bd528-5703-4369-9734-dd318e3487ab, sid: null) (visibleInDoc: true, visibleInLM: true, summary: null, review: null) (name: RACK-1, abstract: false, actor: false, human: false, kind: UNSET, nature: NODE)

But when I do

print(pc.get_name())

I get an error when trying to print the name of the physical component :

org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File “workspace://Python4Capella/framatome/scripts/queries/query.py”, line 102, in
File “…\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py”, line 1321, in call
return_value = get_return_value(
File “…\capella\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\protocol.py”, line 330, in get_return_value
raise Py4JError(
py4j.protocol.Py4JError: An error occurred while calling o816.get_name. Trace:
py4j.Py4JException: Method get_name() does not exist

How Can I handle that please?

Kind Regards,

Valery

Your pc variable reference a Java Object not a Python Object. You can either wrap it in a Python Object:

pc = PhysicalComponent(pc)
print(pc.get_name())

or you can call the Java API:

print(pc.getName())

For more details on passing objects to/from Python/Java APIs you can have a look here.

Hi,

Thanks, It works.

1 Like