sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    ⚠️ Update | Sketchucation Tools 5.0.8 released with licensing improvements and bugfixes Download

    Model observer problem

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 368 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
      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
        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
          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

          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 Login
          • 1 / 1
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement