How to retrieve an observer attached to an entity ?
-
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)
-
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
-
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. -
The most recent and accurate documentation is here:
-
Thanks Jim,
As you can see, get_observers has disappeared from the doc between su6 and 7 -
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.
-
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.
-
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.
-
@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.
-
Me stupid
Advertisement