Model observer problem
-
I need to implement the onPreSaveModel observer,and according the http://www.thomthom.net/software/sketchup/observers/
,it should work in SU version 8.
But according to my testing,the observer works only on the new model.If I close and open again the SU program,the observer is not trigged anymore.My code is simple copied from the API:class MyModelObserver < Sketchup;;ModelObserver def onPreSaveModel(model) UI.messagebox("onPreSaveModel; " + model.to_s) end end # Attach the observer. Sketchup.active_model.add_observer(MyModelObserver.new)Please somebody test it,and if confirmed,I will not touch observers anymore.

-
Use the AppObserver to monitor for new models: http://code.google.com/intl/no/apis/sketchup/docs/ourdoc/appobserver.html
Use the onNewModel and onOpenModel events.
-
Yes,I have thought about this right after sending my post,but want to test first.
Now it is working ok and sorry for blaming observer for this problem.
So this is the working code:class MyModelObserver < Sketchup;;ModelObserver def onPreSaveModel(model) UI.messagebox("onPreSaveModel; " + model.to_s) end end # Attach the observer. Sketchup.active_model.add_observer(MyModelObserver.new) class MyAppObserver < Sketchup;;AppObserver def onNewModel(model) UI.messagebox("onNewModel; " + model.to_s) Sketchup.active_model.add_observer(MyModelObserver.new) # Here is where one might attach other observers to the new model. end def onOpenModel(model) UI.messagebox("onOpenModel; " + model.to_s) Sketchup.active_model.add_observer(MyModelObserver.new) # Here is where one might attach other observers to the new model. end end # Attach the observer Sketchup.add_observer(MyAppObserver.new)
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