api-issue-tracker
api-issue-tracker copied to clipboard
SelectionObserver #onSelectionBulkChange triggering twice
SketchUp Pro v23.1.340 64-bit on Win11
class Observer < Sketchup::SelectionObserver
def onSelectionBulkChange(selection)
puts "onSelectionBulkChange #{Time.now}"
#Sketchup.active_model.set_attribute('qwe', 'asd', Time.now.to_s)
end
end
Sketchup.active_model.selection.add_observer(Observer.new)
Calling it like this will make it work almost as intended except it is not triggered if some object get selected via right click, or if new object is put from library - that object is getting selected but observer is not triggered
Uncomenting set_attribute line will make onSelectionBulkChange to be triggered twice every time you do normal selection change.
I have library of complex DC and a script which detects them placed on scene to adjust some parameters and call $dc_observers.get_latest_class.redraw_with_undo on them. Doing that in combination with onSelectionBulkChange which calls set_attribute makes onSelectionBulkChange to be triggered in infinite loop.
I believe that to have same roots as triggering twice for simple selection.
For the right click and insert of component, it is the method onSelectionAdded which is triggered.
onSelectionBulkChange is not called when the selection is cleared. It is method onSelectionCleared. However, be careful that in most native interactive tools (Move, Rotate, ...) started with no initial selection, the interactive selection process is generating a endless sequence of onSelectionAdded and onSelectionCleared.
Finally, I found that onSelectionBulkChange is called once. If you get it twice, it might be because you started the Selection observer twice.
https://github.com/SketchUp/api-issue-tracker/assets/52487427/b3255d53-ac09-4a18-ab3f-d8afdc0a45f3
Logged as: SKEXT-3930