How to update bpmn xml string in Camunda Modeler plungin


#1

The a Camunda Modeler Plugin, how I can read the bpmn xml string, update it, and show the update in the Camunda Modeler immediately? Where I can find the more detail reference about plugin implementation?

Thanks

Steven


#2

Hi @steventao,

you can inject the bpmn-js instance into the plugin to get the XML.

here are some links where you can find some modeler plugins [1], examples [2] and documentation [3].

[1] https://github.com/camunda/camunda-modeler-plugins
[2] https://github.com/camunda/camunda-modeler-plugin-example
[3] https://github.com/camunda/camunda-modeler/tree/master/docs/plugins

Cheers
kristin


#3

Kristin

Thank you very much for your reply.

How I can inject the bpmn-js instance into the plugin to get the XML? Do you have a simple code?

Thank you again.

Steven


#4

Hi @steventao,

when you take the LoggingPlugin from the documentation, you can use the following line.

LoggingPlugin.$inject = [ 'eventBus', 'bpmnjs' ];

The whole extended LoggingPlugin:

function LoggingPlugin(eventBus, bpmnjs) {
  eventBus.on('shape.added', function() {
    console.log('A shape was added to the diagram!');
  });
 eventBus.on('import.done', function() {
   bpmnjs.saveXML(function(err, xml) {
      if (!err) {
        console.log(xml);
      }
   });
 });
}

LoggingPlugin.$inject = [ 'eventBus', 'bpmnjs' ];

module.exports = {
  __init__: [ 'loggingPlugin' ],
  loggingPlugin: [ 'type', LoggingPlugin ]
};

Cheers
kristin


#5

Kristin

Thank you very much. It works.

Another question, where I can find the information regarding what kind of service can be injected into plugin?

Thanks

Steven