Make/modify model programmatically

Hello all,

Sorry for my stupid question. I’m searching a way to build a model and diagram programmatically using bpmn-js-seed. I guess some API for create/add elements, connect and reflect this immediately to the diagram already exists. Please could you advice me the proper way to searches? Or may be the detailed documentation already exists? :slight_smile:

Thank you!


Could you give us a few more pointers on your use case, i.e. what you would like to achieve by doing it?

I’ve already figured out in something. For example, building the simple model.

o = {};
o.modeler = new BpmnJS({
	container: '#canvas'
o.modeling = o.modeler.get('modeling');
o.elementRegistry = o.modeler.get('elementRegistry');

var i=0;

var process_found = function(){
	rt = o.elementRegistry.get('Process_1'); //get root
	s1 = o.elementRegistry.get('StartEvent_1');//get start event
//append task
	t2 = o.modeling.appendShape(s1,{type:'bpmn:Task'},{x:s1.x+200,y:s1.y+50},rt) = "task_2_gui";
	c1 = t2.incoming[0]; = 'seq_1_2_gui'

//append gateway
	g1 = o.modeling.appendShape(t2,{type:'bpmn:ExclusiveGateway'},{x:t2.x+200,y:t2.y},rt);

	t3 = o.modeling.appendShape(g1,{type:'bpmn:DataObjectReference'},{x:g1.x,y:g1.y+150},rt); = "task_3_gui";

	t4 = o.modeling.appendShape(g1,{type:'bpmn:Task'},{x:g1.x+150,y:g1.y},rt); = "task_4_gui";



The way it is meant to be played. Great to see that you figured that stuff out yourself!

If you’d like to try a more high level API for scripting you can try out the bpmn-js-cli, too. It allows you to do stuff like:

var gateway = cli.append('StartEvent_1', 'bpmn:ExclusiveGateway', '150,0');
var serviceTask = cli.append(gateway, 'bpmn:ServiceTask', '150,0');
var callActivity = cli.append(gateway, 'bpmn:CallActivity', '150,90');


is it possible to specify a label directly when creating an element through the cli interface?
When I use the cli.setLabel() method after creating the element, it takes more and more time depending on how many elements I have already created and this slows down my application…

Kind regards,

Please do not necrobump old topics. Instead link to this thread from new topic.