Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:sellayer [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Select objects on layer =====
 +
 +===== C# =====
 +<code c#>
 +public static Rhino.Commands.Result SelLayer(Rhino.RhinoDoc doc)
 +{
 +  Rhino.Commands.Result rc = Rhino.Commands.Result.Cancel;​
 +  // Prompt for a layer name
 +  string layername = doc.Layers.CurrentLayer.Name;​
 +  rc = Rhino.Input.RhinoGet.GetString("​Name of layer to select objects",​ true, ref layername);
 +  if (rc != Rhino.Commands.Result.Success)
 +    return rc;
 +
 +  // Get all of the objects on the layer. If layername is bogus, you will
 +  // just get an empty list back
 +  Rhino.DocObjects.RhinoObject[] rhobjs = doc.Objects.FindByLayer(layername);​
 +  if (rhobjs == null || rhobjs.Length < 1)
 +    return Rhino.Commands.Result.Cancel;​
 +
 +  for (int i = 0; i < rhobjs.Length;​ i++)
 +    rhobjs[i].Select(true);​
 +  doc.Views.Redraw();​
 +  return Rhino.Commands.Result.Success;​
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Shared Function SelLayer(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result
 +  Dim rc As Rhino.Commands.Result = Rhino.Commands.Result.Cancel
 +  ' Prompt for a layer name
 +  Dim layername As String = doc.Layers.CurrentLayer.Name
 +  rc = Rhino.Input.RhinoGet.GetString("​Name of layer to select objects",​ True, layername)
 +  If rc <> Rhino.Commands.Result.Success Then Return rc
 +
 +  ' Get all of the objects on the layer. If layername is bogus, you will
 +  ' just get an empty list back
 +  Dim rhobjs As Rhino.DocObjects.RhinoObject() = doc.Objects.FindByLayer(layername)
 +  If rhobjs Is Nothing OrElse rhobjs.Length < 1 Then
 +    Return Rhino.Commands.Result.Cancel
 +  End If
 +
 +  For i As Integer = 0 To rhobjs.Length - 1
 +    rhobjs(i).Select(True)
 +  Next
 +  doc.Views.Redraw()
 +  Return Rhino.Commands.Result.Success
 +End Function
 +</​code>​
 +===== Python =====
 +<code python>
 +import Rhino
 +import scriptcontext
 +import System.Guid,​ System.Drawing.Color
 +
 +def SelLayer():
 +    # Prompt for a layer name
 +    layername = scriptcontext.doc.Layers.CurrentLayer.Name
 +    rc, layername = Rhino.Input.RhinoGet.GetString("​Name of layer to select objects",​ True, layername)
 +    if rc!=Rhino.Commands.Result.Success:​ return rc
 +    ​
 +    # Get all of the objects on the layer. If layername is bogus, you will
 +    # just get an empty list back
 +    rhobjs = scriptcontext.doc.Objects.FindByLayer(layername)
 +    if not rhobjs: Rhino.Commands.Result.Cancel
 +    ​
 +    for obj in rhobjs: obj.Select(True)
 +    scriptcontext.doc.Views.Redraw()
 +    return Rhino.Commands.Result.Success
 +
 +if __name__=="​__main__":​
 +    SelLayer()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/sellayer.txt ยท Last modified: 2015/09/14 (external edit)