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

    EntitiesObserver Weirdness

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 239 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.
    • K Offline
      kwalkerman
      last edited by

      OK. I have repeatable steps for the Sketchup:EntitiesObserver that show some STRANGE behavior.

      Use this code:

      ` class KW_EntitiesObserver_Weirdness < Sketchup::EntitiesObserver
      def initialize(*args)
      super
      @m = nil
      end
      def onActiveSectionPlaneChanged(entities)
      end
      def onElementAdded(entities,entity)
      end
      def onElementModified(entities,entity)
      puts "onElementModified: #{entity}"
      if entity.is_a? Sketchup::Material
      @m = entity
      end
      puts "material is #{@m}"
      end
      def onElementRemoved(entities,entity)
      end
      def onEraseEntities(entities)
      end

      def method_missing(meth,*args,&block)
      end
      

      end`

      Materials Weirdness:

      1. In Sketchup, draw a few faces. Enclose them in a group
      2. Load the code above
      3. Select the group
      4. Do the following in the ruby console:

      s = Sketchup.active_model.selection s[0].entities.add_observer KW_EntitiesObserver_Weirdness.new

      1. Now change the material of one of the faces in the group. The observer will fire (at least) twice. In my case it sometimes fires three times - the first two times for the material. The console output should look like this:

      onElementModified: #<Sketchup::Material:0x9c2328> material is #<Sketchup::Material:0x9c2328> onElementModified: #<Sketchup::Face:0xa77588> material is

      For some reason, the material that was stored as @m after the first observer call has been lost. Even more strange, if you add the observer, to Sketchup.active_model.entities everything works fine. The steps for this are:

      1. In Sketchup, draw a few faces.
      2. Load the code above
      3. In the ruby console:

      Sketchup.active_model.entities.add_observer KW_EntitiesObserver_Weirdness.new

      1. Now change the material of one of the faces in the group. Again, the observer fires (at least) twice. In my case it sometimes fires three times - the first two times for the material. In any case @m maintains the reference to the material:

      onElementModified: #<Sketchup::Material:0x98b3c8> material is #<Sketchup::Material:0x98b3c8> onElementModified: #<Sketchup::Material:0x98ae28> material is #<Sketchup::Material:0x98ae28> onElementModified: #<Sketchup::Face:0x98b680> material is #<Sketchup::Material:0x98ae28>

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        What happens if you hold a reference to your observer instance?

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • K Offline
          kwalkerman
          last edited by

          Hi Dan,

          Holding a reference does't make any difference. The only time the reference held by @m is actually stored is when the observer is assigned to Sketchup.active_model.entities.

          Also, I noticed that in cases where I have a new file, and I first add the observer to a group's entities collection, the observer does not alert onElementModified for the material. It only alerts for the face.

          Thanks,

          --
          Karen

          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