This observer interface is implemented to react to events on a definitions collection. To implement this observer, create a Ruby class of this type, override the desired methods, and add an instance of the observer to the collection of interest.
# This is an example of an observer that watches the definitions # collection for new components and shows a messagebox. class MyDefinitionsObserver < Sketchup::DefinitionsObserver def onComponentAdded(definition, definition) UI.messagebox("onComponentAdded: " + definition.to_s) end end # Attach the observer Sketchup.active_model.definitions.add_observer(MyDefinitionsObserver.new)
The onComponentAdded method is called whenever a definition is added to the definitions collection.
Arguments:
Returns:
def onComponentAdded(definitions, definition) UI.messagebox("onComponentAdded: " + definition.to_s) end
The onComponentPropertiesChanged method is called whenever a definition's
name or description are changed.
This does not fire when Glue To, Cuts Opening, or Face Camera settings are
changed.
Returns:
def onComponentPropertiesChanged(definitions, definition) UI.messagebox("onComponentPropertiesChanged: " + definition.to_s) end
The onComponentAdded method is called whenever a definition is removed from the definitions collection. NOTE: This methods fires twice for each Component/Group erased.
Arguments:
Returns:
def onComponentRemoved(definitions, definition) UI.messagebox("onComponentRemoved: " + definition.to_s) end
The onComponentTypeChanged event is fired when a component is converted to a group or vice versa. (In the underlying implementation, Groups are just a special kind of definition that is allowed to only have a single instance.)
Arguments:
Returns:
def onComponentTypeChanged(definitions, definition) UI.messagebox("onComponentTypeChanged: " + definition.to_s) end