sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Pre Save Observer

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 2 Posters 1.1k 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.
    • K Offline
      ktkoh
      last edited by

      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
      
      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        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.

        Hi

        1 Reply Last reply Reply Quote 0
        • K Offline
          ktkoh
          last edited by

          Thanks. That was just what I needed.

          Keith

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            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.

            Hi

            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