I am trying to set the visibility for entities from a LayersObeserver.
So if the tags changes to invisible, is sets some entities, with some logic, to invisible.
If the code is run from the LayersObserver, the entities seem to flicker. It looks like the entities changed to invisible, and back to visible.
I reduced the code to it’s simplest form it still does produces the same effect.t
If I run the code from the onLayerChanged in the console it behaves as expected.
What am I doing wrong ?
module Mories
module MTags
class MyLayersObserver < Sketchup::LayersObserver
def onLayerChanged(layers, layer)
@model = Sketchup.active_model
@entities = @model.entities
@entities.each do |e|
next unless e.is_a?(Sketchup::Drawingelement)
e.visible = false
end
end
end #MyLayersObserver
@layer_observer = MyLayersObserver.new if not @layer_observer
Sketchup.active_model.layers.add_observer(@layer_observer)
end # module MTags
end # module Mories
What do you mean by this? How else can it be done?
The code you posted seams to be more or less okay* (at least no logical problem) and should hide all Drawingelements, if one of the layer visibility changed. I do not see “flicker”, on Windows OS, whatever it is means.
*My version will togle dwge visibility according the changed layer visibility … just to be able to play with it more easy…
(and Use two spaces per indentation level…)
module Mories
module MTags
class MyLayersObserver < Sketchup::LayersObserver
def onLayerChanged(layers, layer)
model = Sketchup.active_model
model.entities.grep(Sketchup::Drawingelement) do |e|
e.visible = layer.visible?
end
end
end #MyLayersObserver
@layer_observer = MyLayersObserver.new if not @layer_observer
Sketchup.active_model.layers.add_observer(@layer_observer)
end # module MTags
end # module Mories
I have just tested and Layer0 is still the active layer.
I am trying to replicate behavior that I saw where the visibility of entities is based on component attributes.
It almost works, except for the fact that the entities don’t hide