Class: Sketchup::AppObserver
Overview
This observer interface is implemented to react to application events. This interface is often used to attach other observers to models as they are opened or started. This ensures that your observers are watching all open models.
For example, when one attaches a SelectionObserver, it is only attached to the Selection collection of a given model. If a 2nd model is opened, the new model's selection changes will not fire selection callbacks unless you've attached a SelectionObserver to the new model as well. By watching for #onNewModel, you can be sure to do so.
To implement this observer, create a Ruby class of this type, override the desired methods, and add an instance of the observer to the application class.
Instance Method Summary collapse
-
#expectsStartupModelNotifications ⇒ Boolean
Called to determine if the observer expects to receive #onNewModel and #onOpenModel calls for the models that are created or opened at SketchUp startup.
-
#onActivateModel(model) ⇒ void
Called when an open model is activated.
-
#onNewModel(model) ⇒ void
Called when the application creates a new, empty model.
-
#onOpenModel(model) ⇒ void
Called when the application opens an existing model.
-
#onQuit ⇒ void
Triggered when SketchUp closes.
-
#onUnloadExtension(ext_name) ⇒ void
Called when the user turns off a Ruby extension.
Instance Method Details
#expectsStartupModelNotifications ⇒ Boolean
Prior to SketchUp 2014, these methods were not being called for the startup models. This issue is now fixed but observers still need to express their intent to receive these calls. This is for back-compatibility with existing scripts which worked around these missing calls by other means. For new code, this method should be implemented and should return true.
Called to determine if the observer expects to receive #onNewModel and #onOpenModel calls for the models that are created or opened at SketchUp startup. This includes the empty initial model, a model opened via command line arguments, or auto-restored models on Mac OS X.
61 62 |
# File 'lib/appobserver.rb', line 61 def expectsStartupModelNotifications end |
#onActivateModel(model) ⇒ void
This method returns an undefined value.
Called when an open model is activated. This is relevant on Mac only which supports multiple documents to be opened simultaneously.
77 78 |
# File 'lib/appobserver.rb', line 77 def onActivateModel(model) end |
#onNewModel(model) ⇒ void
This method returns an undefined value.
Called when the application creates a new, empty model.
90 91 |
# File 'lib/appobserver.rb', line 90 def onNewModel(model) end |
#onOpenModel(model) ⇒ void
If a skp file is loaded via the command line or double-clicking on a skp in explorer (which is also is the command line) then this observer will not be called. The Ruby interpreter in SketchUp is initialized after command line processing so the observer won't be added in time to get the notification.
This method returns an undefined value.
Called when the application opens an existing model.
109 110 |
# File 'lib/appobserver.rb', line 109 def onOpenModel(model) end |
#onQuit ⇒ void
This method returns an undefined value.
Triggered when SketchUp closes. This is useful if you need to clean up anything or store your application state upon close.
121 122 |
# File 'lib/appobserver.rb', line 121 def onQuit end |
#onUnloadExtension(ext_name) ⇒ void
This method returns an undefined value.
Called when the user turns off a Ruby extension. This is useful for detecting if the user is deactivating some critical set of observers, for example, so you can warn them or cache your plugin state.
138 139 |
# File 'lib/appobserver.rb', line 138 def onUnloadExtension(ext_name) end |