How to set Kind and Orientation for Component Exchange?

Hi everyone,

I’m trying to create a Component Exchange in Capella using Python4Capella, but I can’t seem to properly set the Kind and Orientation attributes. The syntax I use directly assigns these attributes.

Interestingly, when I print print(pfip.Orientation), it correctly shows IN, but the element in Capella always appears as UNSET.

Here’s an example of my code snippet:

        cmp_S = find_logical_component_by_name("LC 7",se)
        cmp_D = find_logical_component_by_name("LC 8",se)         

        fe = ComponentExchange()
        fe.set_name('test-' + str(myRow))
        fe.name='test-' + str(myRow)
        fe.Kind = 'FLOW'

        lc_root.get_java_object().getOwnedComponentExchanges().add(fe.get_java_object())

        pfip = ComponentPort()
        pfip.Kind = 'FLOW'
        pfip.Orientation='IN'
        print(pfip.Orientation)
        BehavioralComponent(cmp_S).get_java_object().getOwnedFeatures().add(pfip.get_java_object())

        pfop = ComponentPort()
        pfop.Kind = 'FLOW'
        pfop.Orientation='OUT'
        BehavioralComponent(cmp_D).get_java_object().getOwnedFeatures().add(pfop.get_java_object())
        print(pfop.Orientation)
      

        fe.get_java_object().setSource(pfip.get_java_object())        
        fe.get_java_object().setTarget(pfop.get_java_object())           

Does anyone know why the values are not properly applied in Capella? Is there an additional step I might be missing?

Thanks in advance for your help!

Hi Thierry,

To modify the Capella model you first need to be in a transaction.

With Python4Capella 1.3.0 and newer:

fe.set_kind("FLOW")

and

pfip.set_orientation("IN")

With older version of Python4Capellla, to set the ComponentExchange kind you will need to call the Java API an use the EEnumLiteral:

kind = get_enum_literal("http://www.polarsys.org/capella/core/fa/" + capella_version(), "ComponentExchangeKind", "FLOW")
fe.get_java_object().setKind(kind)
print(fe.get_java_object().getKind())

In the same way you can set the port orientation:

orientation = get_enum_literal("http://www.polarsys.org/capella/core/fa/" + capella_version(), "OrientationPortKind", "IN")
pfip.get_java_object().setOrientation(orientation)
print(pfip.get_java_object().getOrientation())

Thank you very much for your answer, it works using the Java API.

However, I cannot find how to update the KIND for the port, and the simplified API seems to indicate that this is not implemented. Do you know how to work around this issue?

You can use the following code:

port_kind = get_enum_literal("http://www.polarsys.org/capella/core/fa/" + capella_version(), "ComponentPortKind", "FLOW")
pfip.get_java_object().setKind(port_kind)
print(pfip.get_java_object().getKind())

It works,
thank you very much!

1 Like