Issue in Python4Capella with Capella 6.0.0

Hi,
I am testing the new CAPELLA 6.0.0 version. I have an issue with Python4Capella using the script List_logical_functions_in_console.py:

This error does’nt happen with CAPELLA 5.2. did I do something wrong?

thanks
dvd

You did nothing wrong, Your model contains Requirement and Attribute for those requirements. The script tha list all LogicalFunction use get_all_contents_by_type(LogicalFunction) this walks all the model and try to create Python object. At some point we try to create an Attribute but the class is defined in the requirement module.

You can replace the line:

        res = Attribute

with:

        res = getattr(sys.modules["__main__"], "Attribute")

This will only create Attribute if you included the requirement module in your script.

EDIT: I updated the release, you can resinstall to have this fix. I missed this bug before releasing. Thank you for the feedback.

Hi,
I downloaded your latest release. It works indeed.
an other suggestion: I have had to add “include(‘workspace://Python4Capella/simplified_api/requirement.py’)” in many scripts in the sample_scripts folder. It could be fine to also update the Python4Capella project.
see you soon in the forum !
dvd

1 Like

Hi!
Following this thread I have uptated Capella to the 6.0 release and I found that the scripts written before are not working anymore. To give an example I report this test script that I have used to extract Property Values on Logical components, before updating this script used to work as expected but now it doesn’t print anything, I do not know if I am doing something wrong or the script is wrong or I have created property values in the wrong way now, anyway I was hoping for some help.
Thank you.




The result of the script is a completely empty console, so there is no need to send also a screenshot of it, and the script doesn’t give errors, this is the same for all the scripts with which I try to access and print all kinds of property values, requirements and basic mass viewpoint information. In version 5.2 the result was coherent with the model created and property values were printed

Can you add a print statement at the beginning of your script just to make sure the script is executed ?

I created a Capella 6.0.0 environment with PVMT installed from the update site on the download page and Python4Capella 1.1.0.

And it seems to work:

Can you open the error log view and tell me if there is any error in it related to the script ?

image

I added multiple print statements in the code to make sure that it is working and it seems that is running entirely. I am using Capella 6.0 and Python4Capella 1.1.0 like you and the PVMT was installed with the update site as well.
Here it is what the error log says:
The method name “zip” from the module “__EASE_MOD_org_eclipse_ease_modules_platform_ResourcesModule” can not be wrapped because it’s name is reserved

This error can be ignored. And your script is executed. From the output you gave I think no LogicalComponent is found otherwise we would see them. But in the project explorer I can see some LogicalComponent.

Can you try the following code and see if it output something:

# 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 pvmt API
include('workspace://Python4Capella/simplified_api/pvmt.py')
if False:
    from simplified_api.pvmt import *

model = CapellaModel()
model.open("/TMS_test_2/TMS_test_2.aird")
se = model.get_system_engineering()
tested = None
for sf in se.get_all_contents_by_type(LogicalComponent):
    #: :type sf: LogicalComponent
    if sf.get_name() == 'TMS':
        tested = sf
        break

print(tested.get_name())

for pvName in PVMT.get_p_v_names(tested):
    print(pvName,PVMT.get_p_v_value(tested, pvName))

Maybe you can also check that the property values are displayed under the TMS LogicalComponent in the project explorer.

I am sorry but also this script doesn’t work, here it is the error displayed in the console:


I do not know what these errors concern
Property values are displayed correctly in the project explorer as you can see
I do not know why but it seems that the script that I first sent to you “sees” the TMS_test_2 model but “doesn’t see” the logical component in it

tested is None but you have a LogicalComponent named TMS… Try to remove the filter on LogicalComponent. Replace:

se.get_all_contents_by_type(LogicalComponent)

by

se.get_all_contents()

But I don’t see what is happening here… You should try to print your variables see where things are going wrong.

Hi everyone,

I have an issue with the code in order to start developing the scripts for exporting a model and its attributes in .csv.
I have the next code:


And here is the error log:
Hello
Hello
org.eclipse.ease.ScriptExecutionException: java.lang.NullPointerException: Cannot invoke “org.eclipse.emf.ecore.EPackage.getEClassifier(String)” because the return value of “org.eclipse.emf.ecore.EPackage$Registry.getEPackage(String)” is null

Java Stacktrace:
java.lang.NullPointerException: Cannot invoke “org.eclipse.emf.ecore.EPackage.getEClassifier(String)” because the return value of “org.eclipse.emf.ecore.EPackage$Registry.getEPackage(String)” is null
at org.eclipse.python4capella.modules.EMFModule.getEClassifier(EMFModule.java:125)
at jdk.internal.reflect.GeneratedMethodAccessor94.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.ClientServerConnection.sendCommand(ClientServerConnection.java:244)
at py4j.CallbackClient.sendCommand(CallbackClient.java:384)
at py4j.CallbackClient.sendCommand(CallbackClient.java:356)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:106)
at jdk.proxy12/jdk.proxy12.$Proxy25.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:240)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:227)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:189)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:151)
at org.eclipse.ease.modules.EnvironmentModule.include(EnvironmentModule.java:416)
at jdk.internal.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.ClientServerConnection.sendCommand(ClientServerConnection.java:244)
at py4j.CallbackClient.sendCommand(CallbackClient.java:384)
at py4j.CallbackClient.sendCommand(CallbackClient.java:356)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:106)
at jdk.proxy12/jdk.proxy12.$Proxy25.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:240)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:227)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:189)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:242)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)

Do you know what is happening?

Hi Omar,

Don’t hesitate to create your own thread/topic on this forum.

You hare importing Python APIs from two Capella addons: PVMT and Requirements. You need to install the corresponding addons in your Capella so the Python API can delegate to the Java API when needed.

Yvan.

1 Like