我在ADNDevBlog中写了一篇英文博客, 由于比较语言简单,直接在这里黏贴出来分享给大家。
我们无法直接用HideElements() 函数来隐藏一个组Group对象。但是可以分别隐藏组中的对象,达到对这个组进行隐藏的目的。
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 ();
}
转载请复制以下信息:
原文链接: http://blog.csdn.net/joexiongjin/article/details/17915301
作者: 叶雄进
欢迎光临 EaBIM (https://eabim.net/) | Powered by Discuz! X3.2 |