Hi,
We’re encountering an unexpected behavior when using DefinitionsObserver and copy-pasting objects between models.
Context: In our extension, we need to watch for the users copying objects between models and react appropriately when their definitions contain some data from our extension. To do so, we use DefinitionsObserver::onComponentAdded
.
Expected behavior: the observer should fire once for the model in which the object is copied.
Issue: the observer is fired several times, once for each opened model. We’re having users reporting bugs when copy-pasting objects and this might be related. This happens from SU 2017 to 2020.
Reproducing the bug:
Use the following minimal extension: ObserverFiringMultipleTimes.rb · GitHub
- create a plane
- make it a group
- copy
- create a new model
- paste (note: the observer is fired when typing ctrl-v and then again when clicking to validate the copy)
The Ruby console shows something like
attaching observer to the startup model 60
new model 3065
attaching observer to new model 3065
definition 5701 added to model 3065: 1 times
definition 5701 added to model 3065: 2 times
new model 5740
attaching observer to new model 5740
definition 8376 added to model 5740: 1 times
definition 8376 added to model 5740: 2 times
definition 8376 added to model 5740: 3 times
Thanks for your help.