The Revit Platform API uses the Creation.Document.NewGroup() method to select an element or multiple elements or groups and then combines them. With each instance of a group that you place, there is associatively among them. For example, you create a group with a bed, walls, and window and then place multiple instances of the group in your project. If you modify a wall in one group, it changes for all instances of that group. This makes modifying your building model much easier because you can change several instances of a group in one operation.
Code Region 10-9: Creating a Group |
Group group = null; UIDocument uidoc = new UIDocument(document); ElementSet selection = uidoc.Selection.Elements; if (selection.Size > 0) { // Group all selected elements group = document.Create.NewGroup(uidoc.Selection.GetElementIds()); } |
Initially, the group has a generic name, such as Group 1. It can be modified by changing the name of the group type as follows:
Code Region 10-10: Naming a Group |
// Change the default group name to a new name "MyGroup" group.GroupType.Name = "MyGroup"; |
There are three types of groups in Revit; Model Group, Detail Group, and Attached Detail Group. All are created using the NewGroup() method. The created Group's type depends on the Elements passed.
When elements are grouped, they cannot be moved or rotated. If you perform these operations on the grouped elements, nothing happens to the elements, though the Move() or Rotate() method returns true.
You cannot group dimensions and tags without grouping the elements they reference. If you do, the API call will fail.
You can group dimensions and tags that refer to model elements in a model group. The dimensions and tags are added to an attached detail group. The attached detail group cannot be moved, copied, rotated, arrayed, or mirrored without doing the same to the parent group.