Importing layers via Rhino.FileIO

Hi there,

I’m toying around with an “import layers from file” function. I am able to successfully import layers (including tree hierarchy, which is good) using the following code:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

def ImportLayersFromFileTest():
    filename=rs.OpenFileName("Choose file to import layers")
    if not filename: return
    #optional, doesn't change much
    if read_file:
        for layer in layer_list:


This does work to import the layer arrangement without objects, which is what I want. But, some of the layer characteristics are not imported - notably the layer material assignment if any the linetype. OTOH, layer print color and print width are imported.

So the question is this: is there some easy trick I’m missing or do I also need to get the material table separately, add the materials to the file if they do not already exist, and then re-assign them to the imported layers? Same for the linetypes?

I also understand that I will need to do some checking for existing layers and possible conflict resolution, but that’s for later…

Yes to this.

– Dale

We can open 2 different files and copy it.
Why do we need it?

Hi @Helvetosaur , how do you execute this script. I copied the text into a .py file and tried to run it but nothing happened. Does the script work on macs?


No idea if it runs on Mac. To try in Mac V6, save the file somewhere like on your desktop, then use RunPythonScript and browse to the .py file to run it. Then follow the prompts to find the file to read layers from. This is just a test script though, there is much more work to do - however, I’m not able to finish it at the moment.

Thanks for your response Helvetosaur. Eventually figured out what I was doing wrong although I received this error.


Although looking on this page not sure why this error is showing

Would you know the cause of this by any chance.


What version of Rhino are you using?

Hi Steve,

I’m using 5.5.4.

I don’t believe the AllLayers property was made available until Rhino 6

Hi @enki,

With Mac 5.5.4, use File3dm.Layers.

– Dale

Thanks for the resource Dale.

I saw both of those and in V6 in any case, they seemed to do the same thing. Is there a reason to prefer on over the other?

Not really; they are both the same thing under the hood. AllLayers property was added to support some more operations that we couldn’t add with the older Layers property without breaking the SDK.