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!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Adding observers to a group of entities

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 152 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