Undo colors from bpmn-colors example

Hello,
according to this example: https://github.com/bpmn-io/bpmn-js-examples/blob/master/colors/index.html
I choosed option 2 for my purposes.
Could someone explain how to undo the added colors via option 2?

Since adding colors via the modeling API is a command, you can easily do

const commandStack = modeler.get('commandStack');

commandStack.redo();

Thanks for your answer. Your described way I can remove all added colors. Is there also a way how to undo colors from specific elements by using their id?

Well, you could listen for all commands which were fired and then hook into the commandStack to exactly redo this particular command. I’d not recommend to fiddle around with internal functionality. Currently, always the latest command will be redone and not a specific one.

So that saying this seems to be not easily possible. Better would be to save the old colors somewhere and fire a new command setting the old color for this element.

So that means, I have to simply override the added colors with white color, such it looks as before?

it works fine for connections as bpmn:SequenceFlow and bpmn:Association
but it does not work for bpmn:DataInputAssociation.
Is option 2 from the example above not suitable for it?

For further assistance, please share a CodeSandbox that reproduces your issue in a way that we can inspect it.

hello, I am not really sure how to create a CodeSandbox since the project is quite large.
But maybe it helps, when I share the error message:
This only appears when I try to color connections.

image

Do you have any idea what this error-message means?

This is correct. Resetting colors works like this:

modeling.setColor(element, null)

I’ve updated the example accordingly as this is likely a question asked more than once: bpmn-js-examples#77d32aaabf.

According to the error message: this is because I had a set of IDs and some IDs were not available in the Diagram, when I removed some connections for instance. I Could solve the issue by using try catch when setting the color, so invalid Ids can be skipped. Another maybe better approach is to check whether the current IDs in my set are valid and to remove the invalid ones before setting color, but I have no idea if there is a function which is suitable for that.