Determine Object Layer
Demonstrates how to determine which layer a user-specified object is on and print the name.
partial class Examples
{
public static Rhino.Commands.Result DetermineObjectLayer(Rhino.RhinoDoc doc)
{
Rhino.DocObjects.ObjRef obref;
Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out obref);
if (rc != Rhino.Commands.Result.Success)
return rc;
Rhino.DocObjects.RhinoObject rhobj = obref.Object();
if (rhobj == null)
return Rhino.Commands.Result.Failure;
int index = rhobj.Attributes.LayerIndex;
string name = doc.Layers[index].Name;
Rhino.RhinoApp.WriteLine("The selected object's layer is '{0}'", name);
return Rhino.Commands.Result.Success;
}
}
import Rhino
import scriptcontext
import System.Guid
def DetermineObjectLayer():
rc, obref = Rhino.Input.RhinoGet.GetOneObject("Select object", True, Rhino.DocObjects.ObjectType.AnyObject)
if rc!=Rhino.Commands.Result.Success: return rc
rhobj = obref.Object()
if rhobj is None: return Rhino.Commands.Result.Failure
index = rhobj.Attributes.LayerIndex
name = scriptcontext.doc.Layers[index].Name
print("The selected object's layer is '", name, "'")
return Rhino.Commands.Result.Success
if __name__ == "__main__":
DetermineObjectLayer()
