Revit二次开发_快速显示隐藏剖面框

最近遇到一种状况需要经常切换剖面框的可见性,于是想将剖面框的显示与隐藏做成一个按钮,方便切换。
其他类似元素想做成快速切换可见性应该可以使用类似做法。
这次的隐藏对象是剖面框,所以我直接就隐藏元素了。
以下核心代码:
            View activeView = uidoc.ActiveView;
            //过滤剖面框
            FilteredElementCollector elemCollector = new FilteredElementCollector(doc);
            elemCollector.OfCategory(BuiltInCategory.OST_SectionBox);
            Element sectionBox = null;
            //找到当前视图中可以隐藏的剖面框
            foreach(Element e in elemCollector)
            {
                if (e.CanBeHidden(activeView))
                {
                    sectionBox = e;
                    continue;
                }
            }
            List<ElementId> sectionBoxIds = new List<ElementId>();
            sectionBoxIds.Add(sectionBox.Id);
            using(Transaction tran=new Transaction(doc, "快速隐藏工具"))
            {
                tran.Start();
                //判断当前视图中剖面框是否被隐藏
                if (sectionBox.IsHidden(activeView))
                {
                    //取消隐藏
                    activeView.UnhideElements(sectionBoxIds);
                }
                else
                {
                    //隐藏
                    activeView.HideElements(sectionBoxIds);
                }
                tran.Commit();
            }
 
转自:https://blog.csdn.net/imfour/article/details/79007851
原文地址:https://www.cnblogs.com/earthtosky/p/10521984.html