I have used the python4capella add on define my operational actors, entities, capabilities, activities as well as the interaction between the activities. I am creating the diagrams by dragging and dropping them accordingly.
A couple of doubts i have.
The interactions created are actually functional exchanges that become visible at the OA layer between the activities. Because of this I also end up defining my functional chains in the OA layers itself rather than operational processes.
This was fine as long as I was able to portray the meaning across, but when i tried to create entity scenario diagrams to display how a capability is realized dynamically, I am not able to insert these exchanges between the actors/entities. Maybe the capella tool is expecting an interaction but instead having a functional exchange present is the issue, so i tried creating a new interaction between the same elements as well and this isnt working as well.
below is a sample code which shows how I have defined the the interaction via python
model = CapellaModel()
model.open(aird_path)
se = model.get_system_engineering()
oa = se.get_operational_analysis()
root_activity = oa.get_operational_activity_pkg().get_owned_operational_activities()[0]
============================================================
INDEX ACTIVITIES
============================================================
activity_index = {}
for act in se.get_all_contents_by_type(OperationalActivity):
name = act.get_name()
if name.startswith(“OA-”):
activity_index[name] = act
print(“Activities indexed: " + str(len(activity_index)))
print(”")
============================================================
PATCH INTERACTIONS
============================================================
PATCH_INTERACTIONS = [
(
“OA-OP-10 - Command return to dock”,
“OA-MW-08 - Recover to charging location”,
“Manual docking request”
),
(
“OA-OP-14 - Confirm safe conditions for continuation”,
“OA-MW-13 - Accept authorised external instruction”,
“Safe continuation authorization”
)
]
============================================================
HELPERS
============================================================
def get_existing_exchange_names():
names = set()
try:
fe_list = root_activity.get_java_object().getOwnedFunctionalExchanges()
for i in range(fe_list.size()):
fe = fe_list.get(i)
if fe.getName():
names.add(fe.getName())
except:
pass
return names
def find_output_port(activity, port_name):
try:
for p in activity.get_outputs():
if p.get_name() == port_name:
return p
except:
pass
return None
def find_input_port(activity, port_name):
try:
for p in activity.get_inputs():
if p.get_name() == port_name:
return p
except:
pass
return None
============================================================
EXECUTION
============================================================
existing_exchange_names = get_existing_exchange_names()
created = 0
skipped = 0
failed = 0
created_ports = 0
model.start_transaction()
try:
print(“Creating patch interactions…”)
print(“”)
for (src_name, tgt_name, ix_name) in PATCH_INTERACTIONS:
src_act = activity_index.get(src_name)
tgt_act = activity_index.get(tgt_name)
if not src_act:
print(" SKIP (source not found): " + src_name)
skipped += 1
continue
if not tgt_act:
print(" SKIP (target not found): " + tgt_name)
skipped += 1
continue
if ix_name in existing_exchange_names:
print(" SKIP (already exists): " + ix_name)
skipped += 1
continue
try:
out_name = "out_" + ix_name
in_name = "in_" + ix_name
# Source output port
src_out = find_output_port(src_act, out_name)
if src_out is None:
src_out = FunctionOutputPort()
src_out.set_name(out_name)
src_act.get_outputs().add(src_out)
created_ports += 1
# Target input port
tgt_in = find_input_port(tgt_act, in_name)
if tgt_in is None:
tgt_in = FunctionInputPort()
tgt_in.set_name(in_name)
tgt_act.get_inputs().add(tgt_in)
created_ports += 1
# Functional Exchange
fe = FunctionalExchange()
fe.set_name(ix_name)
fe.set_source_port(src_out)
fe.set_target_port(tgt_in)
try:
root_activity.get_owned_functional_exchanges().add(fe)
except:
root_activity.get_java_object().getOwnedFunctionalExchanges().add(
fe.get_java_object()
)
print(" + Created: " + ix_name)
print(" " + src_name + " -> " + tgt_name)
created += 1
except Exception as e:
print(" FAIL: " + ix_name + " | " + str(e))
failed += 1
except:
model.rollback_transaction()
print(“”)
print(“!!! TRANSACTION ROLLED BACK DUE TO ERROR !!!”)
raise
else:
model.commit_transaction()
model.save()