Fetched involving capabilities is always empty

The semantic browser tells me what capability is involving in my system function. However, when I try to fetch involving capabilities on my system function, it returns an empty response.

allSysFuncs = se.get_all_contents_by_type(SystemFunction)
for sf in allSysFuncs:
    print(".....SF - Involving Capabilities.....")
    print(sf.get_involving_capabilities())

Output (cannot attach image as I am restricted to only 1 image per post):

.....SF - Involving Capabilities.....
[]
.....SF - Involving Capabilities.....
[]
.....SF - Involving Capabilities.....
[]
.....SF - Involving Capabilities.....
[]
.....SF - Involving Capabilities.....
[]
.....SF - Involving Capabilities.....
[]

What could be the issue?

EDIT:

Tried approaching from capabilities but same issue, empty sets returned.

capabilities = se.get_all_contents_by_type(Capability)
for capability in capabilities:
    print(capability.get_owned_diagrams())
    print(capability.get_representing_diagrams())
    print(capability.get_involved_functions())

Not sure how to debug

Hello,

I cannot tell why the involving capabilities returns an empty set.
Maybe you can try the same code as the semantic browser uses

List<Object> result = new ArrayList<Object>(0);
    if (object instanceof SystemFunction ) {
      AbstractFunction sf = (AbstractFunction) object;
      EList<Involvement> involvments = sf.getInvolvingInvolvements();
      for (Involvement involvement : involvments) {
        if (involvement instanceof AbstractFunctionAbstractCapabilityInvolvement) {
          InvolverElement involver = involvement.getInvolver();
          if (involver instanceof Capability) {
            result.add(involver);
          }
        }
      }
    }
    
    return result;

I am not sure about how to call java methods in a .py P4C file

Hi,

sf.getInvolvingInvolvements(); can be called in python with sf.get_involving_involvements()
InvolverElement involver = involvement.getInvolver(); can be called with involvement.get_involver()

Unfortunately that does not work.
sf.get_java_object().getInvolvingInvolvements() throws an error
image

To call a query in the semantic browser, you should use the following in your case:

allSysFuncs = se.get_all_contents_by_type(SystemFunction)
for sf in allSysFuncs:
    print(capella_query_by_name(sf, “Involving Capabilities”))

Stephane

I identified my mistake. Even though the returned set is not empty, the size and print functions always show an empty set. But the iteration on the returned values gives me the data I need.


for sf in allSysFuncs:
    involvingCaps = sf.get_involving_capabilities()
    print(len(involvingCaps))
    for ic in involvingCaps:
        print(sf.get_name()+"- "+ic.get_name())

Even though length printed is 0, ic is not empty and contains data. This threw me off initially. But I still don’t know why the length is reported as 0. I was using this as a condition for further loop activities but looks like I need to modify my logic now.

I don’t reproduce this issue with Python4Capella 1.2.0 and the following script:

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

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

aird_path = '/In-Flight Entertainment System/In-Flight Entertainment System.aird'
model = CapellaModel()
model.open(aird_path)

# gets the SystemEngineering and print its name
se = model.get_system_engineering()

allSysFuncs = se.get_all_contents_by_type(SystemFunction)
for sf in allSysFuncs:
    involvingCaps = sf.get_involving_capabilities()
    print(len(involvingCaps))
    for ic in involvingCaps:
        print(sf.get_name()+"- "+ic.get_name())

Maybe you can upgrade your version of Pyhon4Capella ?

Yes, this works. I created a new workspace and now my older script works too! Thanks!

1 Like