Adding Exchange Items to a data package

Hi everyone,
I am pretty new to scripting with Python for Capella. I am currently trying to add Exchange Items from a parsed textual list to a data package located in the Pysical Architecture.

I found an example in the Import_physical_components_from_xlsx.py script. There, the addition is performed by the following line:
#add the new PhysicalComponent
pc_pkg.get_owned_physical_components().add(pc)

I succeed in creating the ExchangeItem and getting the DataPackage. However, I cannot find in the class DataPkg, among all the other possible content getters, the one for the ExchangeItems, in order to use it as in the line above

Any suggestions?
Thank you in advance,

Hi Francesco,

ExchangeItem are contained in the InterfacePkg of the PhysicalArchitecture. Their is no Python API to access it in the Python for Capella API, but you can use the Java API:

myInterfacePkg = myPhysicalArchitecture.get_java_object().getOwnedInterfacePkg()
myInterfacePkg.getOwnedExchangeItems().add(myExchangeItem.get_java_object())
org.polarsys.capella.core.model.helpers.CapellaElementExt.creationService(myExchangeItem.get_java_object())
# myExchangeItem.set...

For more details on Python/Java API you can check the tips and tricks section of the documentation. To remove the false error on the org identifier you can check this section of the documentation.

Let me know if you need more help.

EDIT: I just saw that the DataPkg can also contains ExchangeItem, you can use the instance of DataPkg instead of the InterfacePkg above.

Thank you so much Yvan, it worked in both ways.
As far as I understand, the problem was that I retrieved the data pakage like this, as per the example:
owningDataPkg = se.get_physical_architecture().getOwnedDataPkg()
Which worked but the retrieved object did not support the
getOwnedExchangeItems()
Now, using
se.get_physical_architecture().get_java_object().getOwnedDataPkg()
as per your snippet, everything is fine.

Thanks again,
Francesco

1 Like