Objects Full Layer Name


#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


#2

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


#3

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… :frowning:

–Mitch


Python rs.ObjectLayer() - option to return full layer path
#4

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

#5

Thanks a lot Mitch!


(Steve Baer) #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.