Through Revit UI command, we can hide group by picking it and click the hide command like other elements. Howerver I cannot hide group via API.
Here is the DevelopSharp code I used.
public void hidegroup()
{
Document doc = this.ActiveUIDocument.Document;
Selection sel = this.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element,"Please pick a group");
Element elem = doc.GetElement(ref1);
IList<ElementId> lists = new List<ElementId>();
lists.Add(elem.Id);
Transaction trans = new Transaction(doc);
trans.Start("hidegroup");
doc.ActiveView.HideElements(lists);
trans.Commit ();
}
Launch the command, pick any group, error occurs. The error message is :
Revit failed to execute hidegroup.
A problem has been detected.
Then how can we hide a group? Any tricks?
Solution
Groups cannot be hidden or overridde like ordinary elements. In order to hide a group, we need to hide the element set in that group by HideElements() method. The good aspect is that we can hide part of a group.
Here is the code to hide the whole group.
public void hidegroup()
{
Document doc = this.ActiveUIDocument.Document;Selection sel = this.ActiveUIDocument.Selection;
Reference ref1 = sel.PickObject(ObjectType.Element,"Please pick a group");
Element elem = doc.GetElement(ref1);
IList<ElementId> lists = new List<ElementId>();
Group g = elem as Group;
IList<ElementId> ids = g.GetMemberIds();
Transaction trans = new Transaction(doc);
trans.Start("hidegroup");
this.ActiveUIDocument.ActiveView.HideElements(ids);
trans.Commit ();
}