Creation of physical ports with python4capella

Hello python4capella community! I’m trying to generate physical ports on a generic physical component, but every time I try it I get several errors. There are many predesigned scripts but none of them create several physical ports on a physical component, can you give me a hand, has anyone tried it before? Thanks in advance.

Hi Alex,

There is no Python API for this but we can call the Java API from Python:

pc = PhysicalComponent()
pp = PhysicalPort()


You will have an error on the org symbol because it’s not recognized by PyDev but will be accessible at runtime. You can remove this error.

Note: you need to make all your changes in a transaction.

1 Like

Thank you very much for your quick response! This code works fine, but I’m unable to achieve the same result that by doing it manually.

My code is:

if False:
    from simplified_api.capella import *
if False:
    from utilities.CapellaPlatform import *
from openpyxl import *

aird_path = "/TEST/TEST.aird"
xlsx_path = "/Python4Capella/InputFiles/Components.xlsx"

model = CapellaModel()
se = model.get_system_engineering()
pc_pkg = se.get_physical_architecture().get_physical_system()

# start a transaction to modify the Capella model

    pc = NodePC()
    pp = PhysicalPort()
    # if something went wrong we rollback the transaction
    # if everything is ok we commit the transaction

# save the Capella model

This code creates a physical component (Node) with one physical port. My problem (using Capella 5.1) is that I’m unable to see the proper graphical representation in a [PAB], I cannot see the graphical representation of the physical port itself and the proper relation in the semantic browser. So I don’t get the same effect that doing it manually, I tried everything but I just dont get how to do it. Do you have any idea why this is happening?

Thanks in advance!

1 Like

Can you try to manually refresh your diagram ? I’m not sure if it’s enough for creating the visual representation of the port.

1 Like

Yes it worked! Thank you very much for your fast response!

1 Like