Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:rhinocommonsamples:objectlayer [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Determine Object'​s Layer =====
 +
 +===== C# =====
 +<code c#>
 +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;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function DetermineObjectLayer(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim obref As Rhino.DocObjects.ObjRef = Nothing
 +  Dim rc As Rhino.Commands.Result = Rhino.Input.RhinoGet.GetOneObject("​Select object",​ True, Rhino.DocObjects.ObjectType.AnyObject,​ obref)
 +  If rc <> Rhino.Commands.Result.Success Then
 +    Return rc
 +  End If
 +  Dim rhobj As Rhino.DocObjects.RhinoObject = obref.[Object]()
 +  If rhobj Is Nothing Then
 +    Return Rhino.Commands.Result.Failure
 +  End If
 +  Dim index As Integer = rhobj.Attributes.LayerIndex
 +  Dim name As String = doc.Layers(index).Name
 +  Rhino.RhinoApp.WriteLine("​The selected object'​s layer is '​{0}'",​ name)
 +  Return Rhino.Commands.Result.Success
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +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()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/objectlayer.txt ยท Last modified: 2015/09/14 (external edit)