Labels and Physical Components

Hi again Python 4 Capella Community, I have a question relating the labelling of physical components. We all agree that a good way of creating a PC is:

    pc = NodePC()
    pc_pkg.get_owned_physical_components().add(pc)
    pc.set_name("PC_P4C")

After that, we get the component and drag it to a PAB file:

The component in the left has been generated manually and the one at the right with the previous code. My question is why it doesn’t have label on it? I have tried everything, but it’s not a matter of show/hide label. If we try to delete the components we have for the manual case:


and for the P4C case:

Creating a PC the way I do provoque one element less, in the manual case another element (with a small white ball at the bottom left corner) is created. Somebody can explain me how to achieve the same effect with P4C? For my current job having a visual reference of that label is crucial.

Thanks in advance for your time and help, have a nice day.

I think the part corresponding to your component is missing. Whenever an element is added to the Capella model a Java method is called to apply the Capella logic. Can you try the following code:

    pc = NodePC()
    pc_pkg.get_owned_physical_components().add(pc)
    org.polarsys.capella.core.model.helpers.CapellaElementExt.creationService(pc.get_java_object())
    pc.set_name("PC_P4C")

This might help since I think the Part element is missing in your case.

1 Like

Thanks Yvan for another epic response, it worked nicely for me. I would like to make another question related with that. If I create the component, it’s created inside Physical Architecture/Structure folder, but is there any way to have a direct representation inside de [PAB] Physical System and saving the time of dragging elements to this file manually? I mean a code that create the component and represent it directly, it can be very annoying with you have a lot of components. Thanks again for your time and help, have a nice day!

2 Likes

There is no API at the moment, and even after creating the DDiagramElement you would need to layout it… But as an entry point you can have a look on how it is done by Ecore Tools. I have an open issue on representation API, I’ll add a comment about that.