Adding elements to an existing Rhino Group C++

Hi,

I have a group id of an object:
obj->Attributes().TopGroup();

How can I add additional objects to this group when I know group index?

This should work:

static bool RhinoAddObjectToGroup(
  const CRhinoObject* pObject, 
  int group_index
)
{
  if (nullptr == pObject 
    || group_index < 0
    )
    return false;

  CRhinoDoc* pDoc = pObject->Document();
  if (nullptr == pDoc 
    || group_index >= pDoc->m_group_table.GroupCount()
    || pObject->Attributes().IsInGroup(group_index)
    )
    return false;

  CRhinoObjectAttributes attributes = pObject->Attributes();
  attributes.AddToGroup(group_index);
  
  return pDoc->ModifyObjectAttributes(CRhinoObjRef(pObject), attributes);
}

– Dale