Get_all_contents_by_type Attribute Error

Hello !
I am using the get_all_contents_by_type(LogicalComponent) function in the following script:

model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
NLC = len(se.get_all_contents_by_type(LogicalComponent))

This script is working properly on different project on Capella 6.0. I tried it on a project on Capella 5.2 and had the following issue :

org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File “workspace://Python4Capella/sample_scripts/2_Composant_possede_une_fonction.py”, line 28, in
from py4j.java_collections import SetConverter as _pyease_SetConverter
File “workspace://Python4Capella/simplified_api/capella.py”, line 239, in get_all_contents_by_type
self.except_data = except_data
File “workspace://Python4Capella/java_api/Java_API.py”, line 35, in next
try:
File “workspace://Python4Capella/java_api/Java_API.py”, line 27, in next
from py4j.java_collections import ListConverter as _pyease_ListConverter
File “workspace://Python4Capella/simplified_api/capella.py”, line 164, in get_class
‘’’
AttributeError: module ‘main’ has no attribute ‘Attribute’

Does somebody know why I get this issue? Is it due to Capella 5.2?

There is an open issue with a workaround.

A better way to solve this issue would be changing the line:

        if res == None and e_object.eClass().getName() in ["StringValueAttribute", "IntegerValueAttribute", "EnumerationValueAttribute", "BooleanValueAttribute", "RealValueAttribute"]:
            res = Attribute

by

        if res == None and e_object.eClass().getName() in ["StringValueAttribute", "IntegerValueAttribute", "EnumerationValueAttribute", "BooleanValueAttribute", "RealValueAttribute"]:
            res = getattr(sys.modules["__main__"], "Attribute")

It should work with Capella 5.x and 6.x.

Thanks Yvan. I checked the capella.py script and the line is already the second one, I will try to migrate my project on Capella 6.0 as I have no problem on this version.

1 Like

Maybe you are using Attribute from requirement without importing it ? Try to import it as shown in the linked issue.

I had the same issue. I had a requirement module in the Logical Architecture. When the method scans all elements, it fails unless requirement.py is imported.

1 Like

After changing the line nothing was responding. I decided to delete the P4C project and recreate one and now it works. I can’t explain why…