Change a behaviorPC in NodePC using Py4C

Hello,

another need :slight_smile:

How to change a BehaviorComponent in NodeComponent using py4C?

thanks!!!

Capture d’écran 2026-03-13 164518

This is a special case since the nature change the Python type of the component:

pc = PhysicalComponent()

BEHAVIOR = get_enum_literal("http://www.polarsys.org/capella/core/pa/" + capella_version(), "PhysicalComponentNature", "BEHAVIOR")

pc.get_java_object().setNature(BEHAVIOR)
bpc = BehaviorPC(pc.get_java_object())

Make sure you wrap the Java object to the corresponding Python class. This is not mandatory, but it might save you a lot of debugging later.

Wouah! in live! thanks.

Sorry, I am a mechanic and unfortunately not a computer scientist, I don’t know what means “wrap the Java object to the corresponding Python class”?

The Capella code is written in Java and executed un the JVM (Java Virtual Machine). Python for Capella provides an API (Application Programming Interface) to access Capella objects from Python (an other programming language). To do this some Class are written in Python and reference Java object when instaniated (When you create an instance of PhysicalComponent “engine” for instance). But some Python classes don’t match Java classes one for one. The BehaviaorPC and PhysicalComponent so when you change the attributes of the Java PhysicalComponent, we need to instanciate a new BehaviaorPC to make it reference the Java PhysicalComponent and be coherent with the Python API implementation.

Don’t worry, this is the internals of Python for Capella. You can get more details about the Python and Java sides in the tips and tricks.

1 Like