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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement