Some methods don’t work on selected element

Hello everyone,

I’m trying to get the physical ports of a nodePC using the get_contained_physical_ports() method, which I found on a sample script which I am able to run ; but it doesn’t seem to work on my script with a nodePC that I fetch using the following command which I found in an other sample script :

elem = CapellaElement(CapellaPlatform.getFirstSelectedElement())

To launch my script, I right click on the nodePC in the explorer and I am able to see that it has been correctly fetched, for example elem.get_name() returns the actual name of the nodePC I clicked on to launch the script. However some specific methods such as the one to get the physical ports returns the following error when used on my fetched elem:

‘CapellaElement’ has no attribute ‘get_contained_physical_ports’

I assume this is either because the method is defined for a nodePC whereas my fetched element is of type CapellaElement or because I’m tryin to use java methods on a python object (or conversely). I tried to use the get_java_object method and to cast my elem to a NodePC with no success, it seems I am hitting a dead end. Basically, how can I convert my fetched elem to its actual type to use the methods I want on it ?

As you may see, I am a Python4capella newbie with not that much Java experience so I feel like I’m not seeing the simple fix for this somehow.

If someone knows what I’m doing wrong, and how I can realize it, your help would be much appreciated!

Best,
Theo LM

When you use Python4Capella Java objects from the Capella project are wrapped into Python objects (mode details in the tips and tricks). Here you are wrapping your PhysicalComponent into a CapellaElement and the Python class CapellaElement doesn’t have a method get_contained_physical_ports().

You have two options here either you know the Python class to use:

elem = NodePC(CapellaPlatform.getFirstSelectedElement())

or you don’t and use the generic way by letting Pythonn4Capella choose a Python class for you:

object = CapellaPlatform.getFirstSelectedElement()
elem = EObject.get_class(object)(object)
1 Like