[Python4Capella] Retrieve the name of the NodePC from the BehaviorPC

Hello,

I am trying to create an excel file to extract the functional analysis with the allocation on components (components are for me NodePC, not BehaviorPC, so I want to retrieve the NodePC from the function)

The problem is that at physical level, I can retrieve the BehaviorPC on which the function is allocated to (with method get_allocating_component() on the function). But, I cannot retrieve the NodePC on which the BehaviorPC is deployed, i.e. the “Deploying Physical Components” field.

I have tried to see the information that I can retrieved from the BehaviorPC by using get_all_contents, and I didn’t see the NodePC. Also, I have tried to use get_query_result(“Deploying Physical Components”) but the result was empty.

Is there a way to retrieve the name of the NodePC on which a BehaviorPC is deployed from the object BehaviorPC please ?

On a Behavor PC, you can use myBehaviourPC.get_java_object().getDeployingPhysicalComponents() to get the PC it is deployed on. As you may have several behavior PCs deployments, you may have to do a loop to navigate the hierarchy back up to the NodePC. So something like that (I have not tested it) :
#Iterating on Java objects
pc = myBehaviourPC.get_java_object().getDeployingPhysicalComponents()
while pc.getNature().getName() != “NODE”:
pc = pc.getDeployingPhysicalComponents():
#This line is for you to go back using the Python API:
myPC = NodePC(pc)

Thank you for your reply !

Indeed it work ! The only thing is that getDeployingPhysicalComponents() return a JavaList of one element. So I used pc[0] to retrieve the JavaObject corresponding to the nodePC.

1 Like