• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Adding observers to a group of entities

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 140 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.
  • C Offline
    cjthompson
    last edited by 20 Nov 2009, 15:50

    Has anyone had trouble adding observers to a group of entities?

    It seems to add the observers just fine, but when I try to remove them, it only is able to remove the first entity in the group. Also, if I try remove, then add any observers, it never adds the observers.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 20 Nov 2009, 15:53

      can you paste the code you use to add and remove the observers?

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

      1 Reply Last reply Reply Quote 0
      • C Offline
        cjthompson
        last edited by 20 Nov 2009, 16:08

        Here is an abridged version:

        
        class EntityObserver
        	def onChangeEntity(entity)
        		puts entity.to_s + " changed"
        	end
        end
        
        $entityObserver = EntityObserver.new
        
        def addObserver
        	Sketchup.active_model.selection.each{|entity| entity.add_observer($entityObserver)}
        end
        def removeObserver
        	Sketchup.active_model.selection.each{|entity| entity.remove_observer($entityObserver)}
        end
        

        If you have one entity selected, it adds and removes fine, but if you have more than one entity selected, it only removes the first entity in the selection.

        1 Reply Last reply Reply Quote 0
        • 1 / 1
        1 / 1
        • First post
          1/3
          Last post
        Buy SketchPlus
        Buy SUbD
        Buy WrapR
        Buy eBook
        Buy Modelur
        Buy Vertex Tools
        Buy SketchCuisine
        Buy FormFonts

        Advertisement