say you have this structure:
and you want all layers with the name “Default” to be turned off
Script 1 (using rs.LayerVisibility()
):
import rhinoscriptsyntax as rs
import scriptcontext as sc
import time
def lights_out(layer_list=None):
if layer_list is None:
layers_to_hide = ["Default"]
layer_list = layers_to_hide
else:
pass
for l in sc.doc.Layers:
if l.Name in layer_list:
#print l.Index, l.Name
#l.IsVisible = False
rs.LayerVisible(l.Name,False)
if __name__=="__main__":
ts = time.time()
lights_out()
te = time.time()
print "Elapsed time is {:.2f}".format(te-ts)
Result:
Just the first layer which matches the criteria is turned off
Script 2 (using RhinoCommon
through scriptcontext
):
import rhinoscriptsyntax as rs
import scriptcontext as sc
import time
def lights_out(layer_list=None):
if layer_list is None:
layers_to_hide = ["Default"]
layer_list = layers_to_hide
else:
pass
for l in sc.doc.Layers:
if l.Name in layer_list:
#print l.Index, l.Name
l.IsVisible = False
#rs.LayerVisible(l.Name,False)
if __name__=="__main__":
ts = time.time()
lights_out()
te = time.time()
print "Elapsed time is {:.2f}".format(te-ts)
Result:
How do you even do that semi-turning off sublayers???
Is there a way to turn layers on/off using their index in the layer_table or the id?