Retrieving involved functional chains from functional chain

Dear all,

I have a model where I use funcitonal chains in functional chains and would like to traverse through these. However, when I use the “get_involved_functional_chains” method on a functional chain element, I get “EObject” elements for each involved functional chain instead of “functional chain” type elements. Due to this, I’m missing all the methods to continue to the next level.

Is there any way around this? Am I doing something wrong?

Regards,

Sebastiaan

I don’t think you are doing something wrong. I think a Class implementation might be missing. The method wrapping Java Object in Python Object tries to map Classes by their name (and a bit more). You can have a look at EObject.get_class() in the capella.py file.
To check his hypothesis you can try the following:

print(my_object.get_java_object().toString())

If you are not using CDO it should show the Java Class name. If you are using CDO you can try:

print(my_object.get_java_object().eClass().getName())

From this Class name you can check if there is an implementation in the Python API. If it’s not the case, you can still access the Java API form my_object.get_java_object().

Let me know which Class is missing or if this is an other issue.

Basically there is probably an Object used to connect both FunctionalChain that is not in the Python API.

Dear Yvan,

Thanks for the quick response, it helped me get to the solution. To make it work I updated the FunctionalChain.get_involved_functional_chains() method as follows (inspired by the get_involved_functions method):

def get_involved_functional_chains(self):
        """
        Returns: FunctionalChain[*]
        """
        res = []
        e_object_class = getattr(sys.modules["__main__"], "EObject")
        for involvement in self.get_java_object().getOwnedFunctionalChainInvolvements():
            if involvement.eClass().getName() == 'FunctionalChainReference':
                involvedElement = involvement.getInvolvedElement()
                if involvedElement is not None:
                    specific_cls = e_object_class.get_class(involvedElement)
                    res.append(specific_cls(involvedElement))
        return res

Regards,
Sebastiaan

1 Like

Thank you for sharing your implementation. I opened the following issue.

1 Like