Breakdown creation of operationalActivities

Hi,

I’m trying to create a breakdown of operational activities , means inside of Root Operational Activities

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

# include needed for utilities
include('workspace://Python4Capella/utilities/CapellaPlatform.py')
if False:
    from utilities.CapellaPlatform 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'

    
project_name = aird_path[0:(aird_path.index("/", 1) + 1)]
project = CapellaPlatform.getProject(project_name)
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
model.start_transaction()
oa_pkg = se.get_operational_analysis().get_operational_activity_pkg()

try:
    for activity in se.get_all_contents_by_type(OperationalActivity):
        if activity.get_name().startswith("Root"):
            oa_name='oa test'
            oa=OperationalActivity()
            oa.set_name(oa_name)
            activity.get_owned_operational_activities().add(oa)
            
except:
    model.rollback_transaction()
    raise
else:
    model.commit_transaction()
model.save()

but that get error AttributeError: 'OperationalActivity' object has no attribute 'get_owned_operational_activities'
Then I’ve tried with activity.get_java_object().getOwnedOperationalActivities().add(oa.get_java_object()) and that get error

  _pyease_string_types = (basestring,)
  File "C:\Tools\Capella 5.2.0\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:\Tools\Capella 5.2.0\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 o42467.getOwnedOperationalActivities. Trace:
py4j.Py4JException: Method getOwnedOperationalActivities([]) 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.$Proxy56.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)

As I understand it, it is necessary to trace operation_activity with owned_operational_activities, but I don’t know how exactly to do thi.
Manually we can add an operational activities inside other operational activities. In physical component we can do this , that I’ve tried to replicate but it doesn’t works. Does anyone have any idea how to create an operational activity inside root?

Thanks in advance

You need to use the getOwnedFunctions()Java method… I think OperationalActivity should extends ÀbstractFunction` in the Python API. I opened an issue.

activity.get_java_object().getOwnedFunctions().add(oa)

Then you can use:

for child_oa in activity.get_contained_operational_activities():
    print(child_oa.get_name())

To get the list of contained OperationalActivity.

1 Like

Thanks Yvan for your reply, I will try with this.

1 Like