labs4capella / python4capella

Python for Capella
Eclipse Public License 2.0
52 stars 10 forks source link

Get Incoming and outgoing links from a Component #215

Closed Nelson1905 closed 1 month ago

Nelson1905 commented 5 months ago

Hi,

I would like get with my python code Source and Target elements from Relation linked at a Component, but I didn't found in documentation functions allowing it.

help6

I try severals functions like for example get_incoming_linked_elems() but I get empty lists or errors.

help7

Would you have any leads to share with me ?

ylussaud commented 5 months ago

This sample script doing this.

Nelson1905 commented 1 month ago

Thanks you, I saw this script but it not really that my question. I want to get Allocating_Requirement or Allocated_Requirement specifically from Logical Component. It is possible ?

ylussaud commented 1 month ago

I don't have the needed setup to test but the requirement addon of Capella comes with its own semantic browser queries:

And you can call them with the Python4Capella API, in you case:

myLogicalComponent.get_query_result("Allocated Requirements")
Nelson1905 commented 1 month ago

I already tried it but I got empty lists.

ylussaud commented 1 month ago

Do you have a stack trace ? With Java 17 there is an error because EASE doesn't have a java module name declaration. Maybe that's why the list is empty. Also the str method is not implemented correctly for the JavaList class from Python4Capella which might let you think the list is empty but it might not be.

Nelson1905 commented 1 month ago

When I print the list for elt in diagram.get_represented_elements() : print(elt.get_query_result("Allocated Requirements"), len(elt.get_query_result("Allocated Requirements"))) I don't get stack trace error but I got it : image

ylussaud commented 1 month ago

Did you include the requirement.py module ?

# include needed for the requirement API
include('workspace://Python4Capella/simplified_api/requirement.py')
if False:
    from simplified_api.requirement import *

If it's already the case, you can also try:

myLogicalComponent.get_query_result("Allocated Requirements", Requirement)

Python4Capella automatically wrap Java Object to Python objects and that might be the cause of your issue.

Nelson1905 commented 1 month ago

I resolve it, I needed to select that : image

ylussaud commented 1 month ago

I didn't knew that... requirements queries are not available by default. Thank you for pointing that to me.