An element representing a single instance of a group of elements that may be placed many times in a project or family.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 21.0.0.0 (21.1.1.109)
Syntax
Remarks
Grouping elements is useful when you need to create entities that represent repeating layouts or are common to many building projects, such as hotel rooms, apartments, or repeating floors.
Examples

private void ShowGroupInformation(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element)
{
// Get group information for the selected element
String prompt = null;
if (element.GroupId.Equals(ElementId.InvalidElementId))
{
prompt = "The element isn't in any group.";
}
else
{
Autodesk.Revit.DB.Group group = document.GetElement(element.GroupId) as Autodesk.Revit.DB.Group;
prompt = "The element " + element.Id.IntegerValue + " is in a group.";
prompt += "\nThe group id is " + group.Id.IntegerValue;
prompt += "\nThe group's category is " + group.Category.Name;
prompt += "\nAll group contained element ids are:";
IList<ElementId> memberIds = group.GetMemberIds();
foreach (ElementId id in memberIds)
{
prompt += "\n\t" + id.IntegerValue;
}
}
TaskDialog.Show("Revit",prompt);
}

// Change the default group name to a new name �MyGroup�
group.GroupType.Name = "MyGroup";

public void GetInfo_Group(Group group)
{
string message = "Group : ";
// Show the group type name
message += "\nGroup type name is : " + group.GroupType.Name;
// Show the name of the elements contained in the group
message += "\nThe members contained in this group are:";
IList<ElementId> groupMembers = group.GetMemberIds();
foreach (ElementId memberId in groupMembers)
{
message += "\n\tGroup member id : " + memberId.IntegerValue;
}
message += "\nAll member will now be removed from group.";
group.UngroupMembers();
TaskDialog.Show("Revit",message);
}

Private Sub ShowGroupInformation(document As Autodesk.Revit.DB.Document, element As Autodesk.Revit.DB.Element)
' Get group information for the selected element
Dim prompt As [String] = Nothing
If element.GroupId.Equals(ElementId.InvalidElementId) Then
prompt = "The element isn't in any group."
Else
Dim group As Autodesk.Revit.DB.Group = TryCast(document.GetElement(element.GroupId), Autodesk.Revit.DB.Group)
prompt = "The element " & Convert.ToString(element.Id.IntegerValue) & " is in a group."
prompt += vbLf & "The group id is " + group.Id.IntegerValue
prompt += vbLf & "The group's category is " + group.Category.Name
prompt += vbLf & "All group contained element ids are:"
Dim memberIds As IList(Of ElementId) = group.GetMemberIds()
For Each id As ElementId In memberIds
prompt += vbLf & vbTab + id.IntegerValue
Next
End If
TaskDialog.Show("Revit", prompt)
End Sub

' Change the default group name to a new name �MyGroup�
group.GroupType.Name = "MyGroup"

Public Sub GetInfo_Group(group As Group)
Dim message As String = "Group : "
' Show the group type name
message += vbLf & "Group type name is : " & Convert.ToString(group.GroupType.Name)
' Show the name of the elements contained in the group
message += vbLf & "The members contained in this group are:"
Dim groupMembers As IList(Of ElementId) = group.GetMemberIds()
For Each memberId As ElementId In groupMembers
message += vbLf & vbTab & "Group member id : " + memberId.IntegerValue
Next
message += vbLf & "All member will now be removed from group."
group.UngroupMembers()
TaskDialog.Show("Revit", message)
End Sub