sketchucation logo sketchucation
    • Login
    โ„น๏ธ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    How to retrieve an observer attached to an entity ?

    Scheduled Pinned Locked Moved Developers' Forum
    11 Posts 5 Posters 565 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.
    • Didier BurD Offline
      Didier Bur
      last edited by

      Hi all,

      Everything is in the title.
      Entity.get_observers documentation is empty and I get an error when playing with it:

      Sketchup.active_model.selection[0].get_observers
      

      select an entity and get: undefined method `get_observers' for #Sketchup::Edge:0xe259650

      Anyone has used get_observers so far ?

      DB

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

        I don't know where get_observers is being defined - possibly it is part of Dynamic Components and meant to be used on them. The method is not mentioned in the API documentation. (But this is just my guess.)

        If you need to remove an Observer after attaching it, the only way is to assign it a variable which will persist until you need it.

        
        @my_observer = MyObserver.new
        some_object.add_observer(@my_observer)
        # ... Later...
        some_object.remove_observer(@my_observer)
        
        

        Hi

        1 Reply Last reply Reply Quote 0
        • Chris FullmerC Offline
          Chris Fullmer
          last edited by

          That is odd, I swear I saw that on the docs, but now as I'm looking, I can't find anything on it.

          Chris

          Lately you've been tan, suspicious for the winter.
          All my Plugins I've written

          1 Reply Last reply Reply Quote 0
          • Didier BurD Offline
            Didier Bur
            last edited by

            See the doc about it:

            http://download.sketchup.com/OnlineDoc/gsu6_ruby/Docs/ruby-entity.html#get_observers ๐Ÿ˜ฒ

            My aim is to code a script for "sticky guides" (or lock/unlock guides. It works almost OK but I cannot unlock locked guides without retrieving the observers attached to such guides.
            The locked guides "resist" to the eraser tool (they are not erased) but are erased when using the "Edit/Erase all guides" menu. That's because when deleting more than one entity at once, the observers seem not to trigger.

            DB

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

              The most recent and accurate documentation is here:

              Error 404 (Not Found)!!1

              favicon

              (code.google.com)

              Hi

              1 Reply Last reply Reply Quote 0
              • Didier BurD Offline
                Didier Bur
                last edited by

                Thanks Jim,
                As you can see, get_observers has disappeared from the doc between su6 and 7 ๐ŸŽ‰

                DB

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

                  hm... does sound like an internal method. But now that we know it has been partially documented I'd like to know the full story. ๐Ÿค“

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

                  1 Reply Last reply Reply Quote 0
                  • R Offline
                    RickW
                    last edited by

                    If I remember correctly, .get_observers made a very brief appearance (perhaps beta 6 only?), and was removed due to a high chance of crashing SU. The method description lived on in the documentation, though, causing confusion even today.

                    RickW
                    [www.smustard.com](http://www.smustard.com)

                    1 Reply Last reply Reply Quote 0
                    • Didier BurD Offline
                      Didier Bur
                      last edited by

                      Hi Rick

                      The weird thing is that observers are almost unusable if one can't retrieve them to remove them. Keeping their reference via a variable is difficult because the add_observer method returns true or false, and not the observer itself. ๐Ÿ˜’

                      DB

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

                        @didier bur said:

                        Hi Rick

                        The weird thing is that observers are almost unusable if one can't retrieve them to remove them. Keeping their reference via a variable is difficult because the add_observer method returns true or false, and not the observer itself. ๐Ÿ˜’

                        If you look at Jim's example you see that he keeps a reference to the Observer instance he attaches.

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

                        1 Reply Last reply Reply Quote 0
                        • Didier BurD Offline
                          Didier Bur
                          last edited by

                          Me stupid ๐Ÿ˜ณ

                          DB

                          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