Getting element ancestors in Python4Capella

Hi all,
I would like to write some scripts for exporting/importing SystemFunction hierarchies.
How could I implement the python counterpart of AQL method “ancestors()” to get the parent of current SystemFunction?

You can use:

mySystemFunction.get_container()

This method is declared on the EObject Python class.

Thank you Yvan

Pier Giorgio

Hi all,

Is there an equivalent ‘set_container()’ function? Or do you need to ‘add’ an element to owned elements of a new parent and remove it from the old parent to avoid a corruption?

You need to add the element to a containment EReference. They are usually named owned* in Capella. the get_container() method use the EMF reflective API as a navigation shortcut.
An EObject can only be container in one container, so you don’t need to remove the element from it’s old container. EMF will take care of that for you.

Thanks Yva, that worked.

1 Like