Layers in Rhino.FileIO.File3dm

I’m trying to save (i.e. some geometry created with a python scipt) to different new Rhino-files, each with a different layer structure and file settings.
I started off with FileIO.File3dm class, and found it difficult to navigate around the layers.
FileIO.File3dm.Layer returns something of type Rhino.FileIO.File3dmLayerTable (no documentation ?) which seems to be different from Rhino.DocObjects.Tables.LayerTable.
How does one retrieve Layers in this File3dmLayerTable?
Is there a smarter way to achieve the goal maybe?

It might be a unvalid point, but are you writing this in python?

Edit : have you looked here :

Yes, it’s in python. Is there a way of transforming a IList into a (python) list?

Is this what you want?

import rhinoscriptsyntax as rs

layers = rs.LayerNames()
if layers:
    for layer in layers: print layer

Nope. The File3dm object is not the ActiveDoc.
I’m intending to manipulate it “in background”, without opening it.
If it was, I could have used RhinoDoc.Layers (I guess).

oh i see. let me see what i can do! =)

guessing i can just create a 3dm file and use it since you only want layernames right?

See if this works, save script with the 3dm file you want to read.

import Rhino

def main():
    path = "layer.3dm"
    f3dm = Rhino.FileIO.File3dm.Read(path)
    layerlist = f3dm.Layers
    if layerlist:
        for layer in layerlist: print layer

1 Like

This works! Thanks!
Why is the same thing (addressing Layers as a list) not working below?
The idea is to create the layers “on the go”, depending on what elements will be written to which file, instead of reading a layer structure from a template file upfront.

def main():

    #create a 3dm file:

    #add objects to f3dm to a specified layer (first check if layer already exists, if not, create a new one).....

    #create new layers:


    layerlist = f3dm.Layers
    if layerlist:
        for layer in layerlist: print layer #<< I get an error here, the rest works.

    #save file:

no layers are added, so layerlist is empty.

i have limited experience with this kind of manipulation, i will look into it later :wink:


try adding this


f3dm.Polish() does the job. Many thanks!

No problem!