Dynamically remove shape from canvas

Hello,

I am creating shapes to diagram via

 var canvas = this.get("canvas"),
    elementFactory = this.get("elementFactory");

  var customAttrs = assign({ businessObject: customElement }, customElement);

  var customShape = elementFactory.create("shape", customAttrs);

  return canvas.addShape(customShape);

How can I now safely delete the customShape from canvas if I know the id of the element?

Modeling.removeElements is your friend here.

var elementRegistry = modeler.get('elementRegistry'),
  modeling = modeler.get('modeler');

var element = elementRegistry.get(id);

modeling.removeElements([ element ]);
1 Like