Site Tools

Selecting Objects that are in a Group


Version: Rhino 4
NOTICE: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here


I understand that, using a MRhinoGetObject object, I can select a group of objects. But, how can I select a group of objects non-interactively, or without the user having to pick one of the group members?


To non-interactively select all of the objects that belong to an object group, you must iterate through the geometry table and look for all of the group members.

For example:


public int SelectObjectGroup(MRhinoDoc doc, int group_index, bool bRedraw)
  if( group_index < 0 | group_index >= doc.m_group_table.GroupCount() )
    return 0;
  MRhinoObjectIterator it = new MRhinoObjectIterator(doc,IRhinoObjectIterator.object_state.undeleted_objects,
                                                         IRhinoObjectIterator.object_category.active_and_reference_objects );
  int selected_count = 0;
  foreach (MRhinoObject obj in it)
    if (obj.Attributes().IsInGroup(group_index) && obj.IsSelectable() )
  if (bRedraw)
  return selected_count;

Here is an example, perhaps not a good one, of using the above function.

public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  MRhinoGetObject go = new MRhinoGetObject();
  go.SetCommandPrompt("Select object");
  go.GetObjects(1, 1);
  if (go.CommandResult() != IRhinoCommand.result.success)
    return go.CommandResult();
  IRhinoObject obj = go.Object(0).Object();
  if( obj == null)
    return IRhinoCommand.result.failure;
  int group_count = obj.Attributes().GroupCount();
  if( group_count > 0 )
    Arrayint groups  = new Arrayint(group_count);
    obj.Attributes().GetGroupList(ref groups);
    for (int i = 0; i < groups.Count(); i++)
      SelectObjectGroup(context.m_doc, groups[i], false);
  return IRhinoCommand.result.success;
developer/sdksamples/selectgroupobject.txt ยท Last modified: 2015/09/14 (external edit)