How create breps as group directly

Hi everyone,

I have a RhinoList to create objects to doc as you can see code below. But I want to create breps as a group directly. Is there any method or any way do that?

RhinoList<Brep> storeys = sb.CreateBuilding(crv, doc);

        for(int i = 0; i < storeys.Count; i++)
            doc.Objects.AddBrep(storeys[i]);
        doc.Views.Redraw();

Thanks in advance,
Oğuzhan

Yes, you need to collect the Guid ids that are returned by AddBrep, and then use doc.Groups.AddGroup("name-of-group", list-of-guids)

See also https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_Tables_GroupTable.htm

1 Like

Hi @oguzhankoral,

You can also do this:

RhinoList<Brep> storeys = sb.CreateBuilding(crv, doc);
if (null != storeys && storeys.Count > 0)
{
  var group_index = doc.Groups.Add();
  var attributes = doc.CreateDefaultAttributes();
  attributes.AddToGroup(group_index);

  for (var i = 0; i < storeys.Count; i++)
    doc.Objects.AddBrep(storeys[i], attributes);
  doc.Views.Redraw();
}

– Dale

2 Likes

Hi @dale,

It is directly solved my question and make me awaken about the concept. So glad for answer!

I have two extra wondering,

1- If I want to scale1D in Z-axis of grouped breps in Viewport, using with EventWatchers and EventHandlers, should I use again this group index and attributes to recreate breps with different heights?

2- This new group that we have just created has own different GUID from single GUID’s of breps in the my list? Shortly, Is it new object or referenced from Breps in the my list?

Best
Oğuzhan

Hi @menno,

I guess Dale’s answer solved my question with code example. Even so thanks for your kind answer.

Best,
Oğuzhan