Situation:
I would like to know if one of the rendering information of model changed, then exactly what it was and what it’s new value is.
(No specific goal, just for my own education.)
I’m not a (very) lazy man, so checked myself and get my solution. Easy! ![]()
I can use Class: Sketchup::RenderingOptionsObserver and Class: Sketchup::RenderingOptions
#dirty
class MyROObserver < Sketchup::RenderingOptionsObserver
def onRenderingOptionsChanged(rend_ops, type)
#What is this key?
# key = "BandColor"
# just give an initial value to not get error with partly code
key = "?"
if type == Sketchup::RenderingOptions::ROPSetBackgroundColor
key = "BackgroundColor"
elsif type == Sketchup::RenderingOptions::ROPDrawHiddenGeometry
# Wrong in a docu:
#key = "ROPDrawHiddenGeometry"
key = "DrawHiddenGeometry"
elsif type == Sketchup::RenderingOptions::ROPDrawHiddenObjects
# Wrong in a docu:
#key = "ROPDrawHiddenObjects"
key = "DrawHiddenObjects"
# +61 times elseif,...!?
#elsif type ==
end
puts "Constant: #{type}"
puts "#{key} : #{rend_ops[key]}"
end
end
# Attach the observer.
model_rend_ops = Sketchup.active_model.rendering_options
my_ro_obsever = MyROObserver.new
model_rend_ops.add_observer(my_ro_obsever)
# do not forget
# model_rend_ops.remove_observer(my_ro_obsever)
Not really considering now the usual Ruby API documentation mistakes (two were mentioned in my code), I would like to know the followings:
- Do other developers do the same or similar?
- Do I really heve to go through all of the constant and try to figure out which one is related to what rendering information (option) key?
- Don’t we have a “secret” method to do it more easy or at least a “cat hand written” doc about the
key<>typepairs? - Why do we need a constant here? Wouldn’t it be easier to return the “
key”? Is it a language/OS/version… specific thing? - What is
Sketchup::RenderingOptions::ROPAssigngood for? - What does “
BandColor” key mean?
