Python4Capella allows you to interact with your Capella model using Python. You will be able to create Python scripts to read and write from/to your Capella model.
One basic need of most Capella users is to be able to extract information from Capella models.
In addition to that, the need to be able to import information in a Capella model is also important (to initialize a model, update it...).
However, those needs are currently poorly supported by the tool and existing add-ons.
The idea of this initiative is to provide Python API so that users will be able to develop scripts for Capella.
Scripts will be able to support export / import of data in excel in a generic way, but also at the end could support many more use cases.
The proposed solution is an add-on for Capella allowing to develop and execute scripts in Capella.
(Technically, it encapsulates Eclipse EASE to allow execution of scripts, PyDev for the edition of Python Scripts, and a Python interpreter.)
Here is a preview of the solution:
The solution is based on a 3 levels architecture:
Level | Content | Defined | Used By | |
---|---|---|---|---|
1 | Java API to bridge Python with Java. It is defined in the most generic way to support extraction / import of any kind of information Provided by default with the add-on |
Java developers | Advanced Users to develop technical Python Libraries | |
2 | Python technical libraries. Provides to basic users a set of simplified operations to be used to define high level scripts Some libraries are provided by default, including a simplified definition of Capella metamodel and libraries for most common add-ons (Requirements, PVMT) |
Advanced Capella Users (if default libraries need to be extended) |
Basic Users to build high level scripts | Basic Users to build high level scripts |
3 | High-level user scripts. Used to define the actions to perform (information to be exported / imported) Some examples are provided by default to illustrate the capabilities of the add-on |
Basic Users | Basic Users to execute the scripts |
Legend:
More in details, the solution supports:
Python4Capella relies on a simplified metamodel in order to ease the definition of scripts by end-users.
What are the concepts of interest and their relations ? To which elements from which types can I access from a given element ?
Data packages with classes (for instance 'LogicalArchitecture') and their relations are defined. Class Diagram Blanks can be displayed : [CDB] LogicalArchitecture to have information with concepts/classes related for example to the class 'Logical Architecture'.
This simplified metamodel is defined in a Capella model (using Capella 5.0.0).
Please have a look in the documentation tab of the model to know more about its content.
This model can be retrieved here: https://github.com/labs4capella/python4capella/tree/master/specification/Capella%20Light%20Metamodel
Moreover, a documentation is generated from this model using M2Doc. This documentation can be retrieved here: https://github.com/labs4capella/python4capella/blob/master/specification/M2Doc%20generation/Python4Capella%20Simplified%20Metamodel.docx
PS: the Capella model can be retrieved by cloning the git repository, or by downloading a zip file of the last version of the repository. For this last option, you need to go this the main page (https://github.com/labs4capella/python4capella) and select Code / Download ZIP
This conceptual metamodel is used to generate
You can install Python4Capella in your Capella thanks to an update site. Then you will need to setup Python 3.7 in your environment for release before 2022-08-29. For realeases after 2022-08-29 you can install more recent versions of Python see the Python Installation section.
1) You need to download the zip file from the available releases here. You don’t need to decompress it
2) On the installation dialog, click the “Add…” button at the top to add an update site.
3) Select the “Archive…” button and select the zip file: ‘org.eclipse.python4capella.update.zip’.
4) Select Python4Capella feature.
If you don't know how to install from an update site you can have a look at our video.
You will need to setup Python 3.7 in your environment for release before 2022-08-29. You can use more recent versions of Python but Python4Capella 1.2.0 and before will only run with Python older than version 3.12 (see this issue).
If you are running Windows, you can download the following zip file and unzip it in your Capella installation directory, or any other location:
https://github.com/labs4capella/python4capella/releases/download/2021-07-16/Python37.zip
If you are running Linux or MacOS X, please check your distribution documentation to install Python 3.7 on your system. For realeases after 2022-08-29 you can install more recent versions of Python. In order to run provided sample scripts, you will also need to install openpyxl. You can check the Install new Python package page for more details or directly use your Python interpreter documentation.
You need to import the Python4Capella project that contains the Python API needed to interact with Capella and store your own Python scripts.
Right click in the project explorer and select New > Other menu:
In the New dialog, select the Python4Capella project under the Python4Capella category:
You can click the next then finish buttons to complet the wizard.
At this point you will be prompted to configure your python environment, you can ignore the dialog for the moment and follow the next steps to setup your environment.
You now have the following Python4Capella project in your workspace:
Now you need to reference your Python 3.7 interpreter:
Select the Window > Preferences menu
select the PyDev / Interpreters / Python Interpreter
select the Scripting / Python Scripting (using Py4J) (/!\ not Scripting PyDev)
select the Scripting / Script Locations (needed to contribute user interfaces)
You can click the Apply and close button to finish your setup.
When you will open your fist Python file, you will be prompted by PyDev to define its default configuration:
You can validate the dialog by clicking the OK button.
You can refere to the plugin documentation for usage reference. The documentation is accessible by using the Help > Help contents menu from Capella, then on the right tree, you can select Python4Capella. To get started, you can have a look at the writing script documentation. You can also read the run a Python script page to run one of the provided sample script.
If you open provided scripts, you will notice some errors in them. Those errors can be ignored or even removed. They are related to the use of EASE that allows access to Java objects with the PyDev editor.
EASE is a scripting environment for Eclipse. It allows to create, maintain and execute script code in the context of the running Eclipse instance. Therefore such scripts may manipulate and extend the IDE itself.
The PyDev editor only recognize the Python language, and EASE add a custom way to import other scripts, declare methods and variables. At runtime EASE will be used and everything will work properly.