Focus, selection e zoom at element

How to set focus, selection and zoom at a specific element by your id?

Thanks

1 Like

It is correct the following code to do this?

bpmnJS.get('zoomScroll').reset();

var task = bpmnJS.get('elementRegistry').get('UserTask_0gtca6i');

bpmnJS.get('selection').select(task);
bpmnJS.get('canvas').zoom(1.0, task);

Looks fine!

If you select an element it is focused automatically.

@pedesen, doesn’t work only selecting the element.

OK, maybe I misunderstood. What exactly do you mean by “focus”. Do you expect direct editing to be active, so you can edit text?

Only select the element and show the context panel, doesn’t need edit text.

If you want to open the context pad, just get the module and provide the element you want the context pad to open for:

var task = bpmnJS.get('elementRegistry').get('UserTask_0gtca6i');

bpmnJS.get('contextPad').open(task);
2 Likes

i use bpmn-js-seed and would like open the contextPad from the startEvent

but there is always a TypeError in:

TypeError: element is undefined ==> bpmn-modeler.js (Zeile 3207, Spalte 1)

ContextPadProvider.prototype.getContextPadEntries = function(element) {

if (element.type === ‘label’) {
return actions;
}

}
on line 3207 ==> if (element.type === ‘label’) {

my Code:

var diagramXML =

‘<bpmn:process id=“Process_1” isExecutable=“false”>’ +
‘<bpmn:startEvent id=“StartEvent_1”/>’ +
‘</bpmn:process>’ +

var bpmnModeler = new BpmnModeler({
container: ‘#canvas
});

// after importXML();

var task = bpmnModeler.get(‘elementRegistry’).get(‘StartEvent_1’);
bpmnModeler.get(‘contextPad’).open(task);

Thanks for help

I solved the problem:

after importXML(); execute:

  function createDiagram() {
    bpmnModeler.createDiagram(function(err) {

        // select start event so people can continue to do stuff
        bpmnModeler.get('selection').select(
          bpmnModeler.get('elementRegistry').get('StartEvent_1')
        );
    });
  }

it works with bpmn-js-seed

1 Like

I was working to open context pad of a business object, upon right mouse button click,
your script helped me to manage this.

Thank you

Hey,
I tried the code in the initial post but when I use:

bpmnJS.get('canvas').zoom(1.0, task);

the whole BPMN process disappears. Only when I use 0 it stays the same. The task is selected but the zooming does not work :frowning:
I am using a navigated viewer not a modeller. Is this a bug?

1 Like