sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    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

      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
      • thomthomT Offline
        thomthom
        last edited by

        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

          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
          • First post
            Last post
          Buy SketchPlus
          Buy SUbD
          Buy WrapR
          Buy eBook
          Buy Modelur
          Buy Vertex Tools
          Buy SketchCuisine
          Buy FormFonts

          Advertisement