Site Tools


Sample: Select Objects in an Object's Groups

C#

public class SelectGroupObjecCommand : Command
{
  public override string EnglishName
  {
    get { return "csSelectObjectsInObjectGroups"; }
  }
 
  protected override Result RunCommand(RhinoDoc doc, RunMode mode)
  {
    ObjRef obj_ref;
    var rs = RhinoGet.GetOneObject(
      "Select object", false, ObjectType.AnyObject, out obj_ref);
    if (rs != Result.Success)
      return rs;
    var rhino_object = obj_ref.Object();
    if (rhino_object == null)
      return Result.Failure;
 
    var rhino_object_groups = rhino_object.Attributes.GetGroupList().DefaultIfEmpty(-1);
 
    var selectable_objects= from obj in doc.Objects.GetObjectList(ObjectType.AnyObject)
                            where obj.IsSelectable(true, false, false, false)
                            select obj;
 
    foreach (var selectable_object in selectable_objects)
    {
      foreach (var group in selectable_object.Attributes.GetGroupList())
      {
        if (rhino_object_groups.Contains(group))
        {
            selectable_object.Select(true);
            continue;
        }
      }
    }
    doc.Views.Redraw();
    return Result.Success;
  }
}

VB.NET

Public Class SelectGroupObjecCommand
  Inherits Command
  Public Overrides ReadOnly Property EnglishName() As String
    Get
      Return "vbSelectObjectsInObjectGroups"
    End Get
  End Property
 
  Protected Overrides Function RunCommand(doc As RhinoDoc, mode As RunMode) As Result
    Dim obj_ref As ObjRef
    Dim rs = RhinoGet.GetOneObject("Select object", False, ObjectType.AnyObject, obj_ref)
    If rs <> Result.Success Then
      Return rs
    End If
    Dim rhino_object = obj_ref.[Object]()
    If rhino_object Is Nothing Then
      Return Result.Failure
    End If
 
    Dim rhino_object_groups = rhino_object.Attributes.GetGroupList().DefaultIfEmpty(-1)
 
    Dim selectable_objects = From obj In doc.Objects.GetObjectList(ObjectType.AnyObject) Where obj.IsSelectable(True, False, False, False) Select obj
 
    For Each selectable_object As RhinoObject In selectable_objects
      For Each group As Integer In selectable_object.Attributes.GetGroupList()
        If rhino_object_groups.Contains(group) Then
          selectable_object.[Select](True)
          Continue For
        End If
      Next
    Next
    doc.Views.Redraw()
    Return Result.Success
  End Function
End Class
d Namespace

Python

from Rhino import *
from Rhino.Commands import *
from Rhino.DocObjects import *
from Rhino.Input import *
from scriptcontext import doc
 
def RunCommand():
  rs, obj_ref = RhinoGet.GetOneObject(
    "Select object", False, ObjectType.AnyObject)
  if rs <> Result.Success:
    return rs
  rhino_object = obj_ref.Object()
  if rhino_object == None:
    return Result.Failure
 
  rhino_object_groups = [
    group for group in rhino_object.Attributes.GetGroupList()]
 
  selectable_objects= [
    obj for obj in doc.Objects.GetObjectList(ObjectType.AnyObject)
    if obj.IsSelectable(True, False, False, False)]
 
  for selectable_object in selectable_objects:
    for group in selectable_object.Attributes.GetGroupList():
      if rhino_object_groups.Contains(group):
          selectable_object.Select(True)
          continue
 
  doc.Views.Redraw()
  return Result.Success
 
if __name__ == "__main__":
  RunCommand()
developer/rhinocommonsamples/selectgroupobject.txt ยท Last modified: 2014/06/26 (external edit)