sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Material observer behaviour on OS X

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 334 Views 3 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.
    • pistepilviP Offline
      pistepilvi
      last edited by

      Hi all,

      The behaviour of the MaterialsObserver on OS X is puzzling me: material observers are assigned to active_model.materials, so I would expect them to work on one model only. When creating multiple documents, this works as expected: a onMaterialSetCurrent observer assigned to one model will not respond to changing the active material for another model when using the paint bucket.

      However, when running a Ruby script that changes the active material for Sketchup.active_model, observers from all models react to the event. So when running the script below on one model, then creating a new file and running it for that model, the messagebox will appear twice. After creating yet another model and running the script, it will appear three times and so on. Strangely, when using the paint bucket, only the observer for the current model responds.

      Is this some glitch or actually expected behaviour?

      As I am trying to temporarily switch off the material observer, I am thinking of storing all models and their observers in a hash, so I can just loop through them and switch them off one by one. Does that sound like a sensible solution, or is there a better way to make sure no material observers will react to setting the active material in my script?

      class SU2LUX_materials_observer < Sketchup;;MaterialsObserver
        def onMaterialSetCurrent(materials, material)
          UI.messagebox ("observer reporting; " + Sketchup.active_model.to_s + " " + self.to_s)
        end
      end
      
      puts "creating observer"
      puts myObserver = SU2LUX_materials_observer.new
      puts "assigning observer"
      puts Sketchup.active_model.materials.add_observer(myObserver)
      puts "setting active material"
      Sketchup.active_model.materials.current = Sketchup.active_model.materials[1] 
      
      1 Reply Last reply Reply Quote 0
      • tt_suT Offline
        tt_su
        last edited by

        @pistepilvi said:

        However, when running a Ruby script that changes the active material for Sketchup.active_model, observers from all models react to the event

        Oh? πŸ˜• That's certainly not intended. Though I'm not really surprised given the current state of observers. 😞

        I'll have a look at this.

        1 Reply Last reply Reply Quote 0
        • eneroth3E Offline
          eneroth3
          last edited by

          <offtopic>
          There's a Materials.current method 😲 ?? For my latest project I created a materials observer listening to active material change just so it could be assigned to a variable so I later could know what material is active. How could I have missed this? 😳 cleaning up some code
          </offtopic>

          My website: http://julia-christina-eneroth.se/

          1 Reply Last reply Reply Quote 0
          • tt_suT Offline
            tt_su
            last edited by

            @eneroth3 said:

            <offtopic>
            There's a Materials.current method 😲 ?? For my latest project I created a materials observer listening to active material change just so it could be assigned to a variable so I later could know what material is active. How could I have missed this? 😳 cleaning up some code
            </offtopic>

            Beware that the material might not be in the model yet - in older version of SketchUp it can cause crashes if you try to apply the material to entities.

            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