Hello,
I’m using Python4Capella on Capella 7.0 and I’ve created a script in a Capella project named “Projet”.
I’m trying to automatically create logical components for my diagrams.
With my script, I manage to create two logical components, COMP1 and COMP2, in the Logical System, but I’m facing an issue. When I try to import them into my LAB diagrams, they don’t appear in the list of Components to import, as if they didn’t exist.
However, they do appear in the Logical System tree in the Project Explorer.
Do you have a solution to this problem?
I’m sharing my code in two ways: as a screenshot and as a copy-paste.
Thank you in advance.
My script :
#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 *
#Path to my Capella project
path = ‘/Projet/Projet.aird’
#Opening the model
model = CapellaModel()
model.open(path)
#Starting a transaction
model.start_transaction()
#Retrieving the Logical Architecture
system_engineering = model.get_system_engineering()
logical_architecture = None
for element in system_engineering.get_contents():
if isinstance(element, LogicalArchitecture):
logical_architecture = element
break
if logical_architecture is None:
raise Exception(“can not find Logical Architecture in the model.”)
#Retrieving the interface package from the Logical Architecture
interface_pkg = logical_architecture.get_interface_pkg()
if interface_pkg is None:
raise Exception(“can not find InterfacePkg in Logical Architecture”)
#=== Creating logical components in the Logical System ===
logical_system = logical_architecture.get_logical_system()
if logical_system is None:
raise Exception(“can not find Logical System in Logical Architecture”)
comp1 = LogicalComponent()
comp1.set_name(“COMP1”)
logical_system.get_java_object().getOwnedLogicalComponents().add(comp1.get_java_object())
comp2 = LogicalComponent()
comp2.set_name(“COMP2”)
logical_system.get_java_object().getOwnedLogicalComponents().add(comp2.get_java_object())
#Commit the transaction.
model.commit_transaction()
#Saving the model
model.save()
print(“COMP1 & COMP2 successfully created”)



