Python4Capella – when do I really need to call the Java API?

Hi all,

I’m writing automation scripts with Python4Capella (Capella 7.0.1 + Python4Capella 1.1.3, Simplified API). I’ve noticed that for most high-level elements I can stay entirely in Python, but some relationships still seem to require a direct Java/EMF call.

Example script

python

CopierModifier

# create an Operational Actor
ac1 = OperationalActor()
ac1.set_name("Dummy Act")
pc_pkg_actor.get_owned_entities().add(ac1)

# create an Operational Capability
new_cap = OperationalCapability()
new_cap.set_name("Dummy Cap")
new_cap.set_description("dummy description")
oa_pkg.get_owned_operational_capabilities().add(new_cap)

# simple, high-level link works:
new_cap.get_involved_entities().add(ac1)

# --- trouble starts here ------------------------------------
# how to create the EntityOperationalCapabilityInvolvement?
involvement = org.polarsys.capella.core.data.oa.OaFactory \
               .eINSTANCE.createEntityOperationalCapabilityInvolvement()
involvement.setInvolved(ac1.get_java_object())
new_cap.get_java_object() \
       .getOwnedEntityOperationalCapabilityInvolvements() \
       .add(involvement)
  • Creating the actor and capability works fine with pure Python.
  • Adding the actor to new_cap.get_involved_entities() also works.
  • But the EMF containment list getOwnedEntityOperationalCapabilityInvolvements() has no Python wrapper, so I had to drop down to Java.

What I’m struggling with

  1. Which setters are wrapped, which aren’t?
    I use the metamodel browser for the Python side, but I can’t find a similar overview for the Java services.
  2. How do you discover the correct factory / feature path?
    Manually scanning plugin jars is painful.
  3. Is there a best-practice way to keep scripts future-proof (so they don’t break if internal Java helpers move)?
  4. For this specific case: is there a Python-only helper to create EntityOperationalCapabilityInvolvement, or is a Java call inevitable?

Any pointers to documentation, code examples, or a recommended discovery workflow would be much appreciated.

Thanks in advance for your help!

Hi,

The simplified Python API provided by Python for Capella is specified in this Capella project. Most of it is implemented, you can check the generated Word document for more details (it’s attached to the release).

The simplified API doesn’t cover the all Capella metamodel and the difference is what you will need to call using the Java API.

To discover Methods you can use the Interpreter view and use the AQL interpreter with the content assist (CTRL+SPACE):

aql:self.

You need to select an object from the Capella model, it will bind the self variable to this value.
You can also navigate to the metamodel from the selected object and for instance list all its features:

aql:self.eClass().eAllStructuralFeatures

From the name of the EReference or EAttribute, you can get the method name.

To create an instance of EObject, you can use the following:

e_class = get_e_classifier("http://www.polarsys.org/capella/core/oa/" + capella_version(), "EntityOperationalCapabilityInvolvement")
involvement = create_e_object_from_e_classifier(e_class)

But then involvement is a Java object.

We rely on Java API even when its wrapped in the Python API. If the Capella API introduce breaking changes existing Python scripts might need to be updated including the simplified API.

I hope this will help you understand how and where to find information about the Capella API. Also you can check the tips and tricks page for more details on how to pass objects between Python and Java and also common errors you might encounter.