How do I get the Guid of a group using Rhinocommon?

active_development
rhino5

(Ibrahim Mahmoud) #1

I’m trying to make nested groups within a group, but to do so I’d need to get the nesting group Guids in order to put them in the overarching group. How can I accomplish my goal?


(Dale Fugier) #2

Hi Ibrahim,

Rhino does not support nested groups. However, objects can belong to more than one group.

Does this help?

– Dale


(Ibrahim Mahmoud) #3

Hello Dale,

This is interesting, I didn’t know that. Using this example, is this the process I need to get a nested group feel?

  1. Set List of Points 1 to Group A
  2. Set List of Points 2 to Group B
  3. Set both Lists of Points (1 and 2) to Group C

Thanks,
Ibrahim


(Dale Fugier) #4

How about this:

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  var go0 = new GetObject();
  go0.SetCommandPrompt("Select first set of points");
  go0.GeometryFilter = ObjectType.Point;
  go0.SubObjectSelect = false;
  go0.GetMultiple(1, 0);
  if (go0.CommandResult() != Result.Success)
    return go0.CommandResult();

  var go1 = new GetObject();
  go1.SetCommandPrompt("Select second set of points");
  go1.GeometryFilter = ObjectType.Point;
  go1.SubObjectSelect = false;
  go1.EnablePreSelect(false, true);
  go1.DeselectAllBeforePostSelect = false;
  go1.GetMultiple(1, 0);
  if (go1.CommandResult() != Result.Success)
    return go1.CommandResult();

  // Group "a"
  var points0 = new List<Guid>(go0.ObjectCount);
  foreach (var objref in go0.Objects())
    points0.Add(objref.ObjectId);
  var group_index0 = doc.Groups.Add(points0);

  // Group "b"
  var points1 = new List<Guid>(go1.ObjectCount);
  foreach (var objref in go1.Objects())
    points1.Add(objref.ObjectId);
  var group_index1 = doc.Groups.Add(points1);

  // Group "c"
  var points2 = new List<Guid>(points0.Count + points1.Count);
  points2.AddRange(points0);
  points2.AddRange(points1);
  var group_index2 = doc.Groups.Add(points2);

  return Result.Success;
}

(Ibrahim Mahmoud) #5

Hello Dale,

I’m sorry for such a late response, I only got to fixing it until now. This worked like a charm, thank you very much!

-Ibrahim