Hello there!
Is it possible to get a sequence link from a functional chain using the capabilities of python4capella?
Yes, the easiest way would be to use the semantic browser query:
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()
for functional_chain in se.get_all_contents_by_type(FunctionalChain):
print(type(functional_chain).__name__, functional_chain.get_name())
for functional_exchange in functional_chain.get_query_result("Involved Exchanges"):
print(" -", type(functional_exchange).__name__, functional_exchange.get_name())
This will output something like:
FunctionalChain Watch Imposed Video on Cabin Screen
- FunctionalExchange Audio Signal
- FunctionalExchange Displayed Video
- FunctionalExchange Play Command
- FunctionalExchange Imposed Video Playing Status
- FunctionalExchange Imposed Video Control Command
- FunctionalExchange Audio Stream
- FunctionalExchange Audio Video Media
FunctionalChain Watch Imposed Video on Private Screen
- FunctionalExchange VOD Movie Status
- FunctionalExchange Play Command
- FunctionalExchange Imposed Video Playing Status
- FunctionalExchange Imposed Video Control Command
- FunctionalExchange VOD Movie
- FunctionalExchange Played Audio Video
- FunctionalExchange Audio Video Media
Hello Yvan!
Yes, in the Python API, I discovered the ability to get links to functional exchanges from the functional chain. However, I have not found a way to get the sequence link (see the picture below)
With the help of capella_query_by_name, I could get what I need if a link to the sequence link of the selected functional exchange was presented in the semantic browser. However, there is no such link, but it can be detected by highlighting the sequence link itself (see the picture below) So far, I have no idea how to get to it through a functional exchange.
There is no Python API for that, but you can call the Java API from your Python script:
myCapellaElement.get_java_object().getName()
Here we directly call the Java API getName()
. For your need I had a quick look at the different classed SequenceLink
, FunctionalChainInvolvementLink
but I don’t see the link with the FunctionalExchange
that correspond…
I was able to access the functional exchange associated with the sequence link through aql queries:
ownedSequenceLink - returned to me all sequence links included in the functional chain
ownedSequenceLink.links.involvedElement - returned to me all the functional exchanges related to sequence link (see the picture below).
Сan I use this in the JAVA API to make the same requests? My understanding of the JAVA API is limited and I do not know how it can help me in this task.
Yes, basically each EStrucrutalFeature
form the Capella metamodel produce a getter/setter in the Java API:
for functional_chain in se.get_all_contents_by_type(FunctionalChain):
print(type(functional_chain).__name__, functional_chain.get_name())
sequenceLink = functional_chain.get_java_object().getOwnedSequenceLink()
print(" -", type(sequenceLink).__name__, sequenceLink.getId())
for link in sequenceLink.getLinks():
involvedElement = link.getInvolvedElement()
print(" -", type(link).__name__, link.getId())
print(" -", type(involvedElement).__name__, involvedElement.getName())
I used your version of the code:
sequenceLink = chain.get_java_object().getOwnedSequenceLinks()
print(" -", type(sequenceLink).__name__)
for link in sequenceLink.getlinks():
involvedElement = link.getInvolvedElement()
print(" -", type(link).__name__, link.getId())
print(" -", type(involvedElement).__name__, involvedElement.getName())
however, the console returned the following message, which I cannot interpret, probably a syntax error. All I could figure out was that something was wrong with the request sequenceLink.getlinks (because the console points to a line with this piece of code)
- JavaList
org.eclipse.ease.ScriptExecutionException: Traceback (most recent call last):
File "workspace://Python4Capella/sample_scripts/test.py", line 72, in <module>
# logger.setLevel(logging.DEBUG)
File "C:\Siemens\Capella_star\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\java_gateway.py", line 1321, in __call__
return_value = get_return_value(
File "C:\Siemens\Capella_star\plugins\py4j-python_0.10.9.5-bnd-2odeag\src\py4j\protocol.py", line 330, in get_return_value
raise Py4JError(
py4j.protocol.Py4JError: An error occurred while calling o210.getlinks. Trace:
py4j.Py4JException: Method getlinks([]) 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 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)
It should be getLinks
my bad.
Yvan, thank you for your help! I figured out the syntax a bit and managed to get everything I wanted.