Pulling the names of layers from all drawings in a directory in Rhino for Windows



Does a script exist for extracting the names of all layers in Rhino .3dm files; those that exist by default and those that are created by the user? If I were to attempt to write such a script, what reference should I consult to know which variables to query?


Rhino.LayerNames() (vb) or rhinoscriptsyntax.LayerNames() (python) will get you the names of all the layers in an open document. Or do you want to read an unopened 3dm file?

Layers that exist by default are contained in the template files and those can vary, there is no set standard.



Thanks, Mitch.
I’ll be trying in in python.
Iterating through all the files in a directory, opening them only if it was necessary would be my guess, using a routine for stepping through all the files in a directory, something like what Pascal shared with me about resetting visibility of all files in a directory:



Hi David,

to get the layer names you have to read the file even when not opening it in Rhino. This can take as long as it takes to open the file. Below is an example to start from:

import glob
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def ListLayersInFiles():
    mydirectory = "C:/Users/UserName/Desktop"
    rhino_files = glob.glob(mydirectory + "/*.3dm")
    if len(rhino_files) == 0: return
    for filename in rhino_files:
        if scriptcontext.escape_test(False): return
        f = Rhino.FileIO.File3dm.Read(filename)
        if not f: 
            print "Error reading file:", filename
            print "Layers in: {}".format(filename)
            for layer in f.Layers:
                print " ", layer.Name
            print ""

@stevebaer, i’ve found that if i want to print layer.FullPath instead of layer.Name it does not work, so i tried this instead:

rs.LayerName(layer.Id, fullpath=True)

but it gives an error not finding the provided Id, maybe because it is calling __getLayer using scriptcontext.doc.Layers.Find which seems to be bound to the current document. Is there a way to print the full path in above example ?



Awesome! Thank you.

(Steve Baer) #11

I’ll have to investigate what is causing the FullPath to fail. I’ve logged this at



@stevebaer, thanks for taking a look.