How to auto-layout the ModelInstance created by BPMN model API (the full API)

Could anyone tell me how to auto-layout the BPMN model created by BPMN model API (the full API)? After saving the modelInstance to a file, There is no DI information. How to automatically created that?

Thank you!

Thank you for your answer. But that is for the fluent API. I use the Full API to generate my model. So could you tell me how to create DI information automatically for the model?

THen this: Generating bpmndi for Model API processes ?

Thank you Stephen! That is a great material. But using that approach, I will still have to calculate the x, y, heights and width. And these information has to be specified during generation. Is there a way to auto-layout and generate the DI for an existing BPMN file without DI information. I mean I give it a bpmn XML file without DI, it will output an bpmn XML with proper DI in it and I can use the output bpmn file to display a beautiful diagram.

Actually Eclipse BPMN2 Modeler can and DI information to and display bpmn xml without DI info beautifully. But I don’t know which part of their code does the work.

Can you explain why you need to use the core model api, vs fluent api ?

The reason I use core model api (Full) API instead of the fluent api is that I am actually drawing BPMN diagrams for comments in our code. I that process I need to draw different small parts first then connect them, based on some conditions, into large parts and put the large parts into sub-process and connect the sub-processes. The fluent api isn’t convenient for me to draw in this way. The fluent api only allow to draw according to certain flow. Using the fluent api you are not able to first draw independent parts and then connect them.

Another reason I don’t use fluent api is that it does not support collaboration related elements such as pools and participants.

I really want camunda to have an api to automatically layout diagram and generate DI information for bpmn file generated by the full model api.

I have to generate a model dynamically based on some inputs. In the traditional way I can iterate over the nodes and generate 1.2 or 100 nodes in a simple way. Fluent api uses nested objects and it is difficult to perform a dynamic configuration and I have not found any type of example on an iteration of nodes or the use of even gateways on the …
Is there more information about it?

Using the fluent API works. But you need to do it in 2 or three steps.

  1. Create the base model
  2. Create your reusable element
  3. Edit the base mode to add new instances of your reusable element into the model. You need to create a new instance of the element for each time you want to add it into the base model

Here is a example of adding extension elements through the fluent API: Adding Extensions Properties to Model with Fluent API (Helper Example)

I don’t have a base model.
I have to generate them dynamically.
As the documentation says fluent api does not cover Inclusive Gateways…
This example shows how we can iterate over generated model elements and change some properties not how you can generate these model elements


@alvaro_bu your base model can be “empty” bpmn model instance and then you add to it.

Yes you would have to work within the limits of the fluent API such as not having inclusive.

The reuable model elements you want to inject into your fluent api would be about you coming up with a dsl and then adding in your configured element instances