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?
Thank you!
Edward.
nikku
May 17, 2016, 8:23am
2
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;
o.modeler.createDiagram();
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)
t2.businessObject.di.id = "task_2_gui";
o.modeling.updateProperties(t2,{name:'Scan',id:'task_2'});
c1 = t2.incoming[0];
c1.businessObject.di.id = 'seq_1_2_gui'
o.modeling.updateProperties(c1,{id:'seq_1_2'});
//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);
t3.businessObject.di.id = "task_3_gui";
o.modeling.updateProperties(t3,{name:'Fill',id:'task_3'});
t4 = o.modeling.appendShape(g1,{type:'bpmn:Task'},{x:g1.x+150,y:g1.y},rt);
t4.businessObject.di.id = "task_4_gui";
o.modeling.updateProperties(t4,{name:'Stroke',id:'task_4'});
console.log(o.modeler);
}
setTimeout(function(){process_found()});
3 Likes
nikku
May 18, 2016, 6:34am
4
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');
...
rene51
January 4, 2019, 8:19am
5
Hello,
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,
René