Group object in gh pass to C# component

How to pass group object not rhino one but grasshopper group object to c# component?
What its type is?

It’s too late, by the time a geometry group is passed to a Script input parameter, it will already have been converted into a List<object> where the data inside the list is the ‘ungooified’ stuff. So if you had a Grasshopper.Kernel.Types.GH_GeometryGroup containing two GH_Brep, a GH_Curve and a GH_Point member, you’d get a list containing (Rhino.Geometry.Brep, Rhino.Geometry.Brep, Rhino.Geometry.Curve, Rhino.Geometry.Point3d).

Case in point: groupparsing.gh (9.0 KB)

Thank you.

I have a bunch of different geometries in a group.

To get boundingbox of a group in scripting component, I need:

  1. to get inside of a group
  2. get each bounding box
  3. union all bounding boxes in a group ?

Or it is possible to do in one go?

No, the types inside a group do not necessarily have a base type in common that is bounding box aware. You’ll have to iterate. Easiest is to use the GH_Convert.ToGeometricGoo method, but if you want to inspect each element yourself that will result in fewer instance constructors.

private void RunScript(object G, ref object E)
{
  List<object> group = G as List<object>;
  BoundingBox box = BoundingBox.Empty;

  foreach (object element in group)
    if (element != null)
    {
      IGH_GeometricGoo goo = GH_Convert.ToGeometricGoo(element);
      box = BoundingBox.Union(box, goo.Boundingbox);
    }
  E = box;
}
1 Like