Observers and the Outliner

Hello everyone,

I use several observers in my extension that keep track of whether a component is selected.

I use the SelectionObserver.
The onSelectionBulkChange is triggerd when the user has selected a component in the model and updates the interface.
Now I notice that when I select a component via the Outliner the SelectionObservers are not triggerd, even though the component is selected.

Am I missing something?
I would still expect the SelectionObserver to be triggered when I select a component, even if it is through the Outliner.

Use a polling observer to test what callbacks the SketchUp engine is checking for, with various activities.

class PollingSpy
  def self.attach(obj)
    obj.add_observer( self::new(obj) )
  end
  def initialize(obj)
    @obj = obj
  end
  def detach()
    @obj.remove_observer(self)
    @obj = nil
  end
  def respond_to?(meth)
    puts "SketchUp polled #{self.class}:#{self.inspect}"
    puts "  for a #{meth.to_s} callback,"
    puts "  fired upon object: #{@obj.inspect}"
    super(meth)
  end
end

For a selection, use:

PollingSpy.attach(Sketchup.active_model.selection)

… then test various selection activities.

You will find it is one of the other callbacks that fires for an Outliner selection.

It appears that the documentation “might not trigger” notes are not entirely correct in all cases.

3 Likes

Thank you so much @DanRathbun!
With this code I have found out which observer is being called.

When you select a component or group in the Outliner the “onSelectionAdded” observer is triggered.

According to the API this is unlikely because it says in the notes:

This event might not trigger even if a single element is selected. For instance the Selection tool will trigger #onSelectionBulkChange regardless.

1 Like

Yes, … as I mentioned above …

Please file a documentation issue in the tracker …

Thanks to both you and Dan, I was able to quickly resolve the same issue that you were having, and it worked perfectly. Thanks again.

2 Likes

The API Issue for this is logged as …

https://github.com/SketchUp/api-issue-tracker/issues/603

1 Like