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

    Observer or Event when Changing Model

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 2 Posters 533 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.
    • fredo6F Offline
      fredo6
      last edited by

      I realize that there is no way to capture the event when the user changes the current model BEFORE this happens, so that you can still do something about the current model.

      Am I correct?

      Note: there is an observer for BeforeSave, but you can change the model without saving.

      Fredo

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @fredo6 said:

        Am I correct?

        Generally yes. We have specifically asked for this observer callback. But have not yet been given it.

        You can do periodic or strategically timed tests:

        if @model != Sketchup;;active_model
          # Do something because @model is no longer active
          # but be most careful as changing non-active model
          # would likely crash SketchUp.
        end
        

        or Ruby 2.0:

        
        module Fredo6;;Refinement;;ActiveModel
          refine Sketchup;;Model do
        
            def active?
              self == Sketchup;;active_model
            end
        
          end
        end
        
        using Fredo6;;Refinement;;ActiveModel
        
        if @model.active?
          # do some stuff
        end
        
        

        We also asked for Sketchup::Model#activate() so we can be sure that the model we wish to operate upon is activated.

        But it is not yet implemented either.

        😞

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • fredo6F Offline
          fredo6
          last edited by

          Dan,

          Well, thanks for the confirmation. I think that what I am looking for is a Model.deactivate observer, that is the instant where the model will be taken off current context.

          One small remark. I found that to check if the model has changed, you need to do
          model1.path == model2.path

          The reason is that I noticed in some occasion that you can have different handle for the same model. Here too, it would be good that the API has an explicit way to answer the question on whether the model was changed or not.

          Fredo

          1 Reply Last reply Reply Quote 0
          • Dan RathbunD Offline
            Dan Rathbun
            last edited by

            @fredo6 said:

            One small remark. I found that to check if the model has changed, you need to do
            model1.path == model2.path

            This can fail. If both model's are new models, and not yet saved, the .path() returns an empty string for both, which will eval as equal ( true.)

            @fredo6 said:

            The reason is that I noticed in some occasion that you can have different handle for the same model.

            But that was a bug in older SketchUp versions, wasn't it ?

            I remember it happened when saving the model (most often.) But I thought it was fixed.

            I also remember some programmers testing lower level collection references instead of the model references.

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • fredo6F Offline
              fredo6
              last edited by

              @dan rathbun said:

              But that was a bug in older SketchUp versions, wasn't it ?

              I remember it happened when saving the model (most often.) But I thought it was fixed.

              Maybe, although I am not sure.
              But as you know, supporting older versions is also a requirement, so that, as long as the old tricks work, you finally leave it as it is.

              Fredo

              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