Selecting objects on layers with Rhino python

I’m trying to write a simple script to set the color and line weight of lines based on a list that maps layers to the relevant properties.

This seems to be running into problems with nested layers - rs.IsLayer can find a layer like “parent::child”, but scriptcontext.doc.Objects.FindByLayer won’t - is there another way that I should call the layer / a different way to do this?

My code is linked here:


1 Like


See if this might be helpful:

Hi Chris,

.FindByLayer does not only accept strings but also layer-objects. See if the below example works for you.
It basically gets a list of all possible layer-objects and finds the layer-object with the name to retrieve the objects from.


import rhinoscriptsyntax as rs
import scriptcontext

def main():

    #list of layer names
    layer_names = rs.LayerNames()
    # get a list of all layer objects in the document that are not deleted
    layer_objects = list(layer for layer in scriptcontext.doc.Layers if not layer.IsDeleted)
    for name in layer_names:
        # find layer object with FullPath == name and break out to pass layer_obj in FindByLayer
        layer_obj = None
        for layer_obj in layer_objects:
            if layer_obj.FullPath == name:
        if layer_obj:
            # FindByLayer accepts both names ad layer objects so pass the layer object
            rhobjs = scriptcontext.doc.Objects.FindByLayer(layer_obj)
            print rhobjs
            #catch possible error here

1 Like

Note rs.ObjectsByLayer() should work with full layer names if they are input. Just beware to always supply the full name if you have like-named sublayers…