powerpp
September 11, 2013, 1:38pm
1
Hello,
how can i get the full layername of an object with rhinoscriptsyntax?
rs.ObjectLayer(object) returns the layer name without parent layers.
rs.ParentLayer(layer) returns the full path , but this doesnt work if i have several childlayers with the same name.
Thanks in advance!
Philip
Yes, apparently this functionality is not yet available in Python rhinoscriptsyntax, only vb… Let me see if I can figure it out with RhinoCommon…
–Mitch
Something like this should do it (don’t know if there is an easier way…)
import rhinoscriptsyntax as rs
import scriptcontext as sc
obj=rs.GetObject()
layer=rs.ObjectLayer(obj)
layer_index = sc.doc.Layers.Find(layer, True)
full_name = sc.doc.Layers[layer_index].FullPath
Edit: nope, doesn’t work if there are multiple sublayers with the same name, it just finds the first in the list…
–Mitch
2 Likes
OK, this is much better, sorry for the mispost… --Mitch
import rhinoscriptsyntax as rs
import scriptcontext as sc
objID=rs.GetObject()
obj=sc.doc.Objects.Find(objID)
layer_index=obj.Attributes.LayerIndex
full_name=sc.doc.Layers[layer_index].FullPath
print full_name
3 Likes
stevebaer
(Steve Baer)
September 11, 2013, 11:41pm
6
I just added LayerIds and LayerName for SR7. If you want these functions before SR7, you can get the file at
https://github.com/mcneel/rhinopython/blob/master/scripts/rhinoscript/layer.py Â
I don’t see why you would need to get the file though since Mitch already wrote a great workaround.