Hi all. I do want to create a simple script to switch the visibility of the layer Default between On/Off running the same command. So if the layer Default is On when I do run this script, to switch the visibility of the layer to Off and if the visibility of the layer is Off when I do run the script, to switch the visibility to On. I do created a piece of code that does only the half of the work, I do need a way to get the visibility status of the layer and change to the opposite value.
import rhinoscriptsyntax as rs
l = 'Default'
rs.LayerVisible(l, visible=False)
rs.LayerVisible() returns the current state of the layer visibility if there is no second argument supplied, so to toggle all you need to do is negate the result and feed it back into the method…
import rhinoscriptsyntax as rs
layer="Default"
rs.LayerVisible(layer,not rs.LayerVisible(layer))
import rhinoscriptsyntax as rs
layer_list=["Default","Default1","Default2"] #etc.
for layer in layer_list:
rs.LayerVisible(layer,not rs.LayerVisible(layer))
Note this does not check to see if the layers in your list are actually present - if one or more are not, it will error out. Also it toggles the state of each layer individually, so if some are off and some are on, their states will be inverted. (I assume that is what you want).
Also if it is a very long list of layers you might want to add a rs.EnableRedraw(False) in front of the loop, it might reduce some flickering.