Get list of Rhino layers

Dear experts,
I would like to know the python command to get the list of rhino layers names in a document.
Thanks in advance,

Hi Paxeco
Is this the answer you want?
#coding=utf-8 import rhinoscriptsyntax as rs layer_name = rs.LayerNames() print(layer_name)

Hi 603419608,
Yes, that is what I wanted. I tried it in the Rhino Python editor and it works. However, I need it to develop a Grasshopper component and when I try it in Grasshopper I get the following error message (see image below). Do you know of an alternative way to do this that works in Grasshopper?
Thanks in acvance,

I think the solution is printed in the error message , which is, as error messages go, very informative.
Prior to running rs.LayerNames() you need to set sc.doc = RhinoDoc.ActiveDoc or sc.doc = ghdoc.

Hi menno,
Thanks for you answer. I am not sure how to do this. I typed this:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino as rh
import GhPython as gp

sc.doc = RhinoDoc.ActiveDoc
layers = rs.LayerNames()
print (layers)

and I got the following error message:

Runtime error (UnboundNameException): name ‘RhinoDoc’ is not defined
line 6, in script



sc.doc = Rhino.RhinoDoc.ActiveDoc

I think I forgot to add the namespace “Rhino”.

Yes, now it works! thanks!