Site Tools


Differences

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

Link to this comparison view

developer:rhinocommonsamples:objectiterator [2015/09/14] (current)
Line 1: Line 1:
 +===== Sample: Iterate through Rhino'​s Geometry Table =====
 +
 +===== C# =====
 +<code c#>
 +public class ObjectEnumeratorCommand : Command
 +{
 +  public override string EnglishName
 +  {
 +    get { return "​csObjectEnumerator";​ }
 +  }
 +
 +  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
 +  {
 +    var object_enumerator_settings = new ObjectEnumeratorSettings();​
 +    object_enumerator_settings.IncludeLights = true;
 +    object_enumerator_settings.IncludeGrips = false;
 +    var rhino_objects = doc.Objects.GetObjectList(object_enumerator_settings);​
 +
 +    int count = 0;
 +    foreach (var rhino_object in rhino_objects)
 +    {
 +      if (rhino_object.IsSelectable() && rhino_object.IsSelected(false) == 0)
 +      {
 +        rhino_object.Select(true);​
 +        count++;
 +      }
 +    }
 +    if (count > 0)
 +    {
 +      doc.Views.Redraw();​
 +      RhinoApp.WriteLine("​{0} object{1} selected",​ count,
 +        count == 1 ? ""​ : "​s"​);​
 +    }
 +    return Result.Success;​
 +  }
 +}
 +</​code>​
 +===== VB.NET =====
 +<code vb>
 +Public Class ObjectEnumeratorCommand
 +  Inherits Command
 +  Public Overrides ReadOnly Property EnglishName() As String
 +    Get
 +      Return "​vbObjectEnumerator"​
 +    End Get
 +  End Property
 +
 +  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
 +    Dim object_enumerator_settings = New ObjectEnumeratorSettings()
 +    object_enumerator_settings.IncludeLights = True
 +    object_enumerator_settings.IncludeGrips = False
 +    Dim rhino_objects = doc.Objects.GetObjectList(object_enumerator_settings)
 +
 +    Dim count As Integer = 0
 +    For Each rhino_object As RhinoObject In rhino_objects
 +      If rhino_object.IsSelectable() AndAlso rhino_object.IsSelected(False) = 0 Then
 +        rhino_object.[Select](True)
 +        count += 1
 +      End If
 +    Next
 +    If count > 0 Then
 +      doc.Views.Redraw()
 +      RhinoApp.WriteLine("​{0} object{1} selected",​ count, If(count = 1, "",​ "​s"​))
 +    End If
 +    Return Result.Success
 +  End Function
 +End Class
 +d Namespace
 +</​code>​
 +===== Python =====
 +<code python>
 +from Rhino import *
 +from Rhino.DocObjects import *
 +from Rhino.Commands import *
 +from scriptcontext import doc
 +
 +def RunCommand():​
 +  object_enumerator_settings = ObjectEnumeratorSettings()
 +  object_enumerator_settings.IncludeLights = True
 +  object_enumerator_settings.IncludeGrips = False
 +  rhino_objects = doc.Objects.GetObjectList(object_enumerator_settings)
 +
 +  count = 0
 +  for rhino_object in rhino_objects:​
 +    if rhino_object.IsSelectable() and rhino_object.IsSelected(False) == 0:
 +      rhino_object.Select(True)
 +      count += 1;
 +
 +  if count > 0:
 +    doc.Views.Redraw()
 +    RhinoApp.WriteLine("​{0} object{1} selected",​ count,
 +      ""​ if count == 1 else "​s"​)
 +
 +  return Result.Success
 +
 +if __name__ == "​__main__":​
 +  RunCommand()
 +</​code>​
 +
 +{{tag>​Developer rhinocommon}}
  
developer/rhinocommonsamples/objectiterator.txt ยท Last modified: 2015/09/14 (external edit)