Interaction get_target() and get_source() are not working


I’m trying to use the get_target() and get_source() methods for Interaction but get an AttributeError.

For instance, the following code gets all operational activities and then gets the outgoing interactions for each activity, then attempts to get the target operational activity for each interaction.

se = model.get_system_engineering()

all_op_acts = se.get_all_contents_by_type(OperationalActivity)

for oa in all_op_acts:
    outgoing_interactions = oa.get_outgoing()
    outgoing_interactions_names = [i.get_name() for i in outgoing_interactions]
    target_op_acts = [i.get_target() for i in outgoing_interactions]

However, it throws back the following error:

AttributeError: 'FunctionalExchange' object has no attribute 'get_source'

For some reason it treats the Interaction as FunctionalExchange and the latter does not have a get_source() method

I’m using Capella 6.10 on macOs 13.5.1 and Python 3.11.4

Appreciate your help with this one.

There is something off with the simplified API. Both Interaction and FunctionalExchange from the Python API refere to the Java API FunctionalExchange. When wrapping a Java object to a Python object we try to get the most specific type from the Python API. In this case it returns FunctionalExchange even if we specify a preference for the Interaction class. This is an issue that need some thinking since it impact the behavior of the all API.

Meanwhile as a workaround, there is a FunctionalExchange.get_source_port() and FunctionalExchange.get_target_port() and FunctionalExchange.get_source_function() and FunctionalExchange.get_target_function().
Or you can wrap the Java object in an Interaction:

1 Like

Thanks Yvan for your help.

1 Like