Pre Save Observer
-
I am trying to implement a pre save observer. This is an example of the file. This works on the current model if I load the file after the model is open. However if I bring up a new model and then save it this observer does not see the save operation. Suggestions on how to make it work on each model I save??
Keith
require 'sketchup.rb' # This is an example of an observer that watches the # model save event. module K2WS class MyModelObserver < Sketchup;;ModelObserver def onPreSaveModel(model) UI.messagebox("PreSaveObserver") end end # Attach the observer. Sketchup.active_model.add_observer(MyModelObserver.new) end # K2WS
-
When you start a new model, or open a model the existing model - the one with the observer attached is destroyed.
You need to attach an observer to the new model. Use an AppObserver to be notified when you open a model, or when you start a new model.
-
Thanks. That was just what I needed.
Keith
-
I'm glad it helped.
What I said is true on Windows because there is ever only one Model.
On a Mac you can have more than one model opened. But you still probably need to attach your observers when new models are created.
Advertisement