您的位置:首页 > 其它

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

2018-01-08 22:14 387 查看
难得不用加班,闲下来写两行代码。

最近遇到一种状况需要经常切换剖面框的可见性,于是想将剖面框的显示与隐藏做成一个按钮,方便切换。

其他类似元素想做成快速切换可见性应该可以使用类似做法。

这次的隐藏对象是剖面框,所以我直接就隐藏元素了。

以下核心代码:

            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();

            }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Revit二次开发