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)
Advertisement