Edit api create new element

Looking at the tutorials there are example for editing elements that already are present, however there is no description of how to create a new element e.g. as a leaf of a folder for example. Is it possible to provide an example on how to create a new element in a folder that exisits? It would be good to have an example of the best way to do this.

Hello Craig,
All Capella elements can be extended using Capella Studio.
When you declare a new Class in the .data.vptext file and define the “extends” information, it means that your new kind of element will be stored under the extended Capella element.
For example, if you define those two classes:
On one hand, the Mass element extends the Capella PhysicalComponent element. Thus Masses will be created under Physical Components.
On the other hand, the NewObject element extends the Capella PhysicalFunctionPkg. Thus NewObjects will be created in this package, next to the Root Physical Function.

Hello Aurélien,
Thanks for the response. It is not exactly what I was asking, but my question was probably not very clear. I was wondering how you would create a new element e.g a physical function in a model using the API through a Capella plugin. For Example how would I create a new physical function in a package?
Thanks Craig

Hello again,
Indeed I completely misunderstood your question…
So, in order to programmatically create a new element, you need to use a Factory.
You can find the list of the different Factories here:
You will have to write something like this:
Then you may need to define the different attributes of your new function (name …).
Finally you need to define the attachment to the parent element.
For this, you will have to write something like this:
(assuming that myFuncPkg is your PhysicalFunctionPkg)

Hello Aurélien,
i am also trying to create new elements with the methods that you have described here. Currently there are still some things i need to solve.
I created a simple viewpoint for a physical architecture which has a string and a double (checkbox). The idea is that when this checkbox is pressed, a Java function executes and creates new function blocks.
My data file looks as following:
I have a Java condition which checks if “simulinkmodelsfound” is pressed and with this Java method i want to create new elements.
Within the Java condition that is triggered i import the PaFactory (org.polarsys.capella.core.data.pa.PaFactory, instead of org.polarsys.capella.core.data.gen.PaFactory which is listed in
https://wiki.polarsys.org/Capella/Tutorials/Extensibility/Me tamodel).
I am able to run the plugin in debug mode but no elements are created when i press the button in the plugin. Do you have an idea on why it is not generating any elements? Thank you very much in advance,

Hey Aurelien,
I managed to read out All the Components in a Capella model but the type of the components that are read are of the class “DNodeContainer” instead of specific Capella nodes, such as “PhysicalComponent”.
When i want to write new components, it is only possible to link new DNodecontainers to the existing models and not PhysicalComponents.
Is there somewhere a way to get the Capella-specific classes instead of this more generic “DNodeContainer”?
I have following model with 3 Physical Components and 1 Physical Actor. Inside “PC 1” there is my block which triggers the Java function.
When i trigger the Java function from “SimulinkBlock”, New blocks are created for each of the components as in following picture. Because i only can create DNodeContainers, Capella cannot understand the type and only white boxes are created.
In following the code that is triggered is shown. There i check if “finalel” is an instance of “PhysicalComponent” which is never true. On the contrary it is always “DNodeContainer”. Because of this, i can only link another DNodecontainer and no PhysicalComponent.
Is it possible to directly get the Capella Specific Components out of the Capella Model instead of this “DNodeContainer” type?
Thank you very much in advance. Please let me know if more info is required.

Hello Jefs,
Several points:
1/ I am not sure to understand why you want to create new
model elements when checking this parameter “Simulinkmodelsfound”
What do you want to do with those new elements? Do you need to specify additional information on those?
2/ There was something wrong with the elements you created in your first message
Here, you create a function package “myFuncPkg” and a function “myNewFunc”.
Then you attach the new function to the new function package.
However, the function package is also a new element and thus is not attached to any existing element in your model.
That’s why the new elements did not appeared in your model.
You need to find the right existing elements to which you will attach the new elements you create.
3/ In your last message you are mixing several things.
You need to understand that a Capella model is made of two different things:

  • the model which contains
    model elements like the components, the functions and so on
    This is the definition of your system, the need and everything. It contains all the relations between model elements (allocation, deployment, realization…), and all their attributes (name, summary, description…)
  • a set of
    diagrams which are representations of your
    model elements
    In those diagrams, model elements are represented by
    graphical objects
    There is 4 types of
    graphical objects:
  • DNode : a simple box
  • DNodeContainer : a box which can contain other boxes
  • DBorderedNode : a box attached to the border of another box (used for the representation of the ports in Capella)
  • DEdge : the lines between the boxes (which can have different representations such as arrows…)
    So in your last message, your code is doing the following:
    In all the diagrams which exist in you model
    In all the boxes which appear in those diagrams
    It creates a new box which do not refer to any model element
    This is not what you should do!
    However I am not sure what you really want to do.
    Do you really need to create new
    model elements? Will you add any information / relation to those elements once create?
    Or do you only want to modify the graphical representation of the Physical Components?

Hey Aurélien,
thanks for your quick response!
I am not a Java developer so the code itself will not be very neat.
Indeed the code that i have currently does not make a lot of sense from a functional perspective. I am just basically trying to read out or create all different Capella components. Depending on the use case i will use it for. (I based myself on:
https://wiki.polarsys.org/Capella/Tutorials/Extensibility/Ed it)
For example, i would be interested in parsing a folder structure of Simulink blocks and automatically creating a LAB diagram with logical components depending on this folder structure. I was thinking to do this by adding the plugin block to an empty diagram, add the root location of the simulink project as a string input to this block and press the button on this block.
To be able to do this, i will have to be able to generate Capella elements (That can later be extended in Capella itself).
For now i only managed to create and link “DNodeContainers” with which i cannot do much afterwards in Capella.
So basically, is there an elegant way to access the Capella diagram where the plugin block is in, and create Capella components in it? (Thus not only the DNodeContainers that i get now).
The elements from the diagram that are returned are of type DDiagramElement:
I would like to extract Capella specific components from these elements. But they cannot be found in the type hierarchy:
Hopefully my questions is now more clear.
Best regards and thanks,

Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.