Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5791

[python] set layer visibility issue

$
0
0

@ivelin.peychev wrote:

say you have this structure:

image

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:
image

Just the first layer which matches the criteria is turned off :thinking:

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:
image

How do you even do that semi-turning off sublayers??? :woozy_face::upside_down_face::zipper_mouth_face::face_with_raised_eyebrow:

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 5791

Trending Articles