for some purpose, I want to iterate all layers in a document in python
well, there are several ways, for example:
(1) get the list of the names of all layers, so we can write:
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
list = rs.LayerNames()
for current_layer in list:
layer = sc.doc.Layers.FindName(current_layer)
print layer
(2)get the number of all layers, then use for
loop:
import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc
layer_num = rs.LayerCount()
for current_layer in range(layer_num):
layer = sc.doc.Layers.FindIndex(current_layer)
print layer
it seems that I find the third way, use sc.doc.Layers.GetEnumerator()
, but I don’t know how to continue. I guess it well be a more advanced solution.
anyone can help me ? thank you