Hello,
I am very new to Python and also to Python for Capella…
I am trying to write a script to export the list of Physical Links and associated ports in an Excel file.
I get an error message with the get_connected_physical_ports() method :
It seems that the underlying getConnectedPhysicalPorts() does not exist.
Extract of my source code :
->>>>>>>>>>> Source code extract start >>>>>>>>>>>
writing excel file header
worksheet = workbook.active
worksheet.title = ‘Physical links’
worksheet[“A1”] = ‘Physical link’
worksheet[“B1”] = ‘Origine Port’
worksheet[“C1”] = ‘Destination Port’
i=2
retrieving elements from the model
all_PhysicalLinks = se.get_all_contents_by_type(PhysicalLink)
for PhysicalLink in all_PhysicalLinks:
worksheet[“A” + str(i)] = PhysicalLink.get_name()
ConnectedPhysicalPorts = []
ConnectedPhysicalPorts = PhysicalLink.get_connected_physical_ports()
Port1 = ConnectedPhysicalPorts[0]
Port2 = ConnectedPhysicalPorts[1]
worksheet[“B” + str(i)] = Port1.get_name()
worksheet[“C” + str(i)] = Port2.get_name()
i = i +1
Save the xlsx file
workbook.save(xlsx_file_name)
<<<<<<<<<<<< Source code extract end <<<<<<<<<<<<
Line 82 corresponds to
ConnectedPhysicalPorts = PhysicalLink.get_connected_physical_ports()
The error message in console is
->>>>>>>>>>> Console content start >>>>>>>>>>>
py4j.Py4JException: An exception was raised by the Python Proxy. Return Message: Traceback (most recent call last):
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\org.eclipse.ease.lang.python.py4j_0.7.0.I201907020902\pysrc\ease_py4j_main.py”, line 186, in runcode
exec(compiled, self.locals)
File “L/PyDev - Essais01/mf_Export_list_of_physical_links_to_xlsx.py”, line 82, in
‘’’
File “L/Python4Capella/simplified_api/capella.py”, line 2455, in get_connected_physical_ports
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\java_gateway.py”, line 1322, in call
answer, self.gateway_client, self.target_id, self.name)
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\protocol.py”, line 332, in get_return_value
format(target_id, “.”, name, value))
py4j.protocol.Py4JError: An error occurred while calling o403.getConnectedPhysicalPorts. Trace:
py4j.Py4JException: Method getConnectedPhysicalPorts([]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
at py4j.Gateway.invoke(Gateway.java:274)
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 com.sun.proxy.$Proxy30.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:236)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:226)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:245)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:309)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\py4j-python_0.10.9.3-bnd-2odeag\src\py4j\clientserver.py”, line 581, in _call_proxy
return_value = getattr(self.pool[obj_id], method)(*params)
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\org.eclipse.ease.lang.python.py4j_0.7.0.I201907020902\pysrc\ease_py4j_main.py”, line 335, in executeScript
return self.executeCommon(code_text, self.interp.runcode, filename)
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\org.eclipse.ease.lang.python.py4j_0.7.0.I201907020902\pysrc\ease_py4j_main.py”, line 313, in executeCommon
execution_result = code_exec(code_text, filename)
File “C:\SC\PSYS\capella142_py4c\eclipse\plugins\org.eclipse.ease.lang.python.py4j_0.7.0.I201907020902\pysrc\ease_py4j_main.py”, line 213, in runcode
except Exception:
TypeError: catching classes that do not inherit from BaseException is not allowed
at py4j.Protocol.getReturnValue(Protocol.java:476)
at py4j.reflection.PythonProxyHandler.invoke(PythonProxyHandler.java:108)
at com.sun.proxy.$Proxy30.executeScript(Unknown Source)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.internalExecute(Py4jScriptEngine.java:236)
at org.eclipse.ease.lang.python.py4j.internal.Py4jScriptEngine.execute(Py4jScriptEngine.java:226)
at org.eclipse.ease.AbstractScriptEngine.inject(AbstractScriptEngine.java:245)
at org.eclipse.ease.AbstractScriptEngine.run(AbstractScriptEngine.java:309)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
<<<<<<<<<<<< Console content end <<<<<<<<<<<<
Thank you very much for your help.