To Deploy Behavioral PC into Node PC using P4C Scripts

Hi Yvan,

Please can you share the P4C scripting to Deploy Behavioral PC into Node PC?.

Thanks
Balamurali.

You will need to create a PartDeploymentLink and add it to the ownedDeploymentLinks of your Node PC Part. The link reference the Part of the Behavioral PC so you also need to get the Part referencing the Behavioral PC.

# we get the Node PC Part and Behavior PC Part
my_node_pc_part = None
my_behavior_pc_part = None
part_e_class = get_e_classifier("http://www.polarsys.org/capella/core/cs/" + capella_version(), "Part")
for part in JavaList(eAllContentsByType(se.get_java_object(), part_e_class), EObject):
    if part.get_java_object().getName() == "My Behavior PC":
        my_behavior_pc_part = part.get_java_object()
    if part.get_java_object().getName() == "My Node PC":
        my_node_pc_part = part.get_java_object()
    if my_behavior_pc_part and my_node_pc_part:
        break

print(my_node_pc_part)
print(my_behavior_pc_part)

# we create the PartDeploymentLink
link = create_e_object("http://www.polarsys.org/capella/core/pa/deployment/" + capella_version(), "PartDeploymentLink")
link.setLocation(my_node_pc_part)
link.setDeployedElement(my_behavior_pc_part)

model.start_transaction()
try:
    # add the link to the Node PC Part
    my_node_pc_part.getOwnedDeploymentLinks().add(link)
except:
    # if something went wrong we rollback the transaction
    model.rollback_transaction()
    raise
else:
    # if everything is ok we commit the transaction
    model.commit_transaction()

# save the Capella model
model.save()
1 Like

Thanks Yvan for sharing the scripts.

Regards,
Balamurali.

1 Like