123456789_123456789_123456789_123456789_123456789_

Class: Sketchup::InstanceObserver Abstract

Relationships
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Sketchup::EntityObserver

Overview

This class is abstract.

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.

This observer interface is implemented to react to component instance events.

Note that you may also attach InstanceObservers to Groups.

Examples:

# This is an example of an observer that watches a specific instance
# for open edit actions and shows a messagebox.
class MyInstanceObserver < Sketchup::InstanceObserver
  def onOpen(instance)
    puts "onOpen: #{instance}"
  end

  def onClose(instance)
    puts "onClose: #{instance}"
  end
end

# Attach the observer. (This example assumes that your first definition
# in the model contains an instance to attach the observer to. This
# example should work with a model where Sang or Bryce are present in
# the template.)
model = Sketchup.active_model
model.definitions[0].instances[0].add_observer(MyInstanceObserver.new)

Version:

  • SketchUp 6.0

Instance Method Summary

  • #onClose(instance) ⇒ nil

    The #onClose method is called when an instance is “closed,” meaning an end user was editing a component’s geometry and then exited back into the parent’s editing space.

  • #onOpen(instance) ⇒ nil

    The #onOpen method is called when an instance is “opened,” meaning an end user has double clicked on it to edit its geometry.

EntityObserver - Inherited

#onChangeEntity

The #onChangeEntity method is invoked when your entity is modified.

#onEraseEntity

The #onEraseEntity method is invoked when your entity is erased.

Instance Method Details

#onClose(instance) ⇒ nil

The #onClose method is called when an instance is “closed,” meaning an end user was editing a component’s geometry and then exited back into the parent’s editing space.

Examples:

def onClose(instance)
  puts "onClose: #{instance}"
end

Parameters:

Version:

  • SketchUp 6.0

#onOpen(instance) ⇒ nil

The #onOpen method is called when an instance is “opened,” meaning an end user has double clicked on it to edit its geometry. This is particularly useful if your plugin is dynamically drawing geometry or performing transformations in global space, since when in “edit component” mode all transformations and positions are returned in relation to the current component’s origin.

This method will tell you when a user has entered edit mode, and you can then use Model#active_path and Model#edit_transform methods to determine any corrections you need to make to your transformations.

Examples:

def onOpen(instance)
  puts "onOpen: #{instance}"
end

Parameters:

Version:

  • SketchUp 6.0