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!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    How observers work ?

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 5 Posters 2.0k Views 5 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.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      @thomthom said:

      @dan rathbun said:

      (1) Jim did not subclass from Sketchup::ShadowInfoObserver

      No need. Su doesn't care. Just implement the methods required.

      I knew that Sketchup does't (currently,) check the observer's superclass.

      But isn't it a matter of good Ruby programming practice?

      And, what if (in the future,) Google implements some built-in methods, constants, etc. in the superclass that will need to be inherited by your custom observer's subclass(es)? You'd have to go and edit and re-release all your plugins that use observer's.

      I'm not here much anymore.

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

        @dan rathbun said:

        But isn't it a matter of good Ruby programming practice?

        Probably is. But combining several observers into one class sure is handy at times. πŸ˜‰

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

        1 Reply Last reply Reply Quote 0
        • P Offline
          pvbuero
          last edited by

          @unknownuser said:

          This works for me:

          This works for me too. Perfect. Thanks a lot.

          I thought I was doing something basically wrong because the code above was't "my code". It was from the API documentation... strange πŸ˜’

          1 Reply Last reply Reply Quote 0
          • P Offline
            pvbuero
            last edited by

            I'm still having trouble with this observer.
            Now the event is fired whenever I change the shadowinfo settings and I see a messagebox (see below). That's fine so far.
            Observer.png

            But I'm not able to overwrite this messagebox-method with my own method.
            I wrote the following:

            class SO < Sketchup;;ShadowInfoObserver
                def onShadowInfoChanged(info, type)
                    UI.messagebox("test the observer")
                end
            end
            

            ...but still the same message as shown above appears..
            What have I done wrong ?

            Thanks for your help...
            MD

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

              @pvbuero said:

              I'm still having trouble with this observer.
              ...but still the same message as shown above appears..
              What have I done wrong ?

              Jim's version is still being loaded, probably AFTER your version, so your's gets redefined by his version.

              Also it's best to restart Sketchup for testing. (Otherwise you have to detatch the old observer instance, redefine the variable to point to a new instance of your new observer class, and attach the new observer instance.)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • P Offline
                pvbuero
                last edited by

                @dan rathbun said:

                Jim's version is still being loaded, probably AFTER your version, so your's gets redefined by his version.
                Also it's best to restart Sketchup for testing. (Otherwise you have to detatch the old observer instance, redefine the variable to point to a new instance of your new observer class, and attach the new observer instance.)

                Hello Dan,

                I have restarted sketchup and I've no idea where Jim's version should come from ? I deleted it and replaced it by my code...

                Thanks MD

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

                  Have you tried giving it a unique name?
                  Or even better wrap your code into a unique module to avoid namespace collision.

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

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

                    @pvbuero said:

                    I have restarted sketchup and I've no idea where Jim's version should come from ? I deleted it and replaced it by my code...

                    It has to come froma script file in the Plugins folder.

                    if you write a script that opens the Console first thing (name it !!!first.rb or something with exclamtion points so it gets loaded first,) and then in that set
                    $VERBOSE=true
                    you will see warnings issued to the Console whenever a method is overwritten.

                    The problems you have are because you have too many things in the Plugins folder.
                    This is why ThomThom suggested MOST scripts should be in subfolders (and loaded with a loader script.)

                    The easiest way to test is to rename the Plugins folder to something else "_Plugins"
                    and make a new Plugins folder.
                    Put the script under test in the new folder and load Sketchup. Test it.
                    If it works then there is a problem script in the "real" Plugins folder.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • P Offline
                      pvbuero
                      last edited by

                      Thanks a lot. You're answers are a great help for me as an absolute beginner... πŸ’­
                      ... I'll try your suggestions this evening and give you a feedback.

                      1 Reply Last reply Reply Quote 0
                      • P Offline
                        pvbuero
                        last edited by

                        Hello,

                        thanks to Dans suggestion πŸ‘ I solved the problem. There was a second testing script which obviously overwrote the script I was working on. I deleted it and everything worked as I intended.

                        Thanks to all of you for your help.
                        MD

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

                          @dan rathbun said:

                          @thomthom said:

                          @dan rathbun said:

                          (1) Jim did not subclass from Sketchup::ShadowInfoObserver

                          No need. Su doesn't care. Just implement the methods required.

                          I knew that Sketchup does't (currently,) check the observer's superclass.

                          But isn't it a matter of good Ruby programming practice?

                          And, what if (in the future,) Google implements some built-in methods, constants, etc. in the superclass that will need to be inherited by your custom observer's subclass(es)? You'd have to go and edit and re-release all your plugins that use observer's.

                          Kind of seem to be by design: http://forums.sketchucation.com/viewtopic.php?f=180&t=17047&start=150#p171636

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

                          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