Class: Sketchup::SelectionObserver

Inherits:
Object
  • Object
show all

Overview

This observer interface is implemented to react to selection events. To implement this observer, create a Ruby class of this type, override the desired methods, and add an instance of the observer to the objects of interests.

Examples:

# This is an example of an observer that watches the selection for
# changes.
class MySelectionObserver < Sketchup::SelectionObserver
  def onSelectionBulkChange(selection)
    puts "onSelectionBulkChange: #{selection}"
  end
end

# Attach the observer.
Sketchup.active_model.selection.add_observer(MySelectionObserver.new)

Version:

  • SketchUp 6.0

Instance Method Summary collapse

Instance Method Details

#onSelectionAdded(selection, entity) ⇒ nil

Note:

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

Examples:

def onSelectionAdded(selection, entity)
  puts "onSelectionAdded: #{entity}"
end

Parameters:

Returns:

  • (nil)

See Also:

Version:

  • SketchUp 6.0

#onSelectionBulkChange(selection) ⇒ nil

The #onSelectionBulkChange method is called whenever items are added or removed from the selection set.

The #onSelectionBulkChange callback will not trigger if the selection is cleared by clicking on empty model space. Use the #onSelectionCleared method to catch this case.

Examples:

def onSelectionBulkChange(selection)
  puts "onSelectionRemoved: #{selection}"
end

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#onSelectionCleared(selection) ⇒ nil

The #onSelectionCleared method is called when the selection is completely emptied.

Examples:

def onSelectionCleared(selection)
  puts "onSelectionCleared: #{selection}"
end

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#onSelectionRemoved(selection, entity) ⇒ nil

Note:

Due to a bug in SketchUp this event doesn't trigger. Instead onSelectedRemoved is called.

Examples:

class MySelectionObserver < Sketchup::SelectionObserver
  # Note that there is a bug that prevent this from being called. Instead
  # listen to onSelectedRemoved until the bug is fixed.
  def onSelectionRemoved(selection, entity)
    puts "onSelectionRemoved: #{entity}"
  end
  # To work around this you must catch this event instead until the bug is
  # fixed:
  def onSelectedRemoved(selection, entity)
    # You can forward it to the correct event to be future compatible.
    onSelectionRemoved(selection, entity)
  end
end

# Attach the observer.
Sketchup.active_model.selection.add_observer(MySelectionObserver.new)

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0