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]