sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Model observer problem

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 223 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • voljankoV Offline
      voljanko
      last edited by

      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. 😞

      SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        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.

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • voljankoV Offline
          voljanko
          last edited by

          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)
          

          SuSolid.com - solid check - solid repair- solid intersection check - weight plugin

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement