BIM World
A Professional BIM Learning Platform


Revit Secondary Development: How to Quickly Display Hidden Section Boxes

It’s uncommon to have free time without overtime work, even just to write a few lines of code.

Recently, I needed to frequently toggle the visibility of a section box. To simplify this process, I decided to create a button that can easily show or hide the section box.

This approach can also be applied to quickly switch visibility for other similar elements.

In this case, the target is the section box, so the solution involves directly hiding or showing the element.

Here is the core code:

View activeView = uidoc.ActiveView;
// Filter for section boxes
FilteredElementCollector elemCollector = new FilteredElementCollector(doc);
elemCollector.OfCategory(BuiltInCategory.OST_SectionBox);
Element sectionBox = null;
// Find section boxes that can be hidden in the current view
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, “Quick Hide Tool”))
{
tran.Start();
// Check if the section box is hidden in the current view
if (sectionBox.IsHidden(activeView))
{
// Unhide section box
activeView.UnhideElements(sectionBoxIds);
}
else
{
// Hide section box
activeView.HideElements(sectionBoxIds);
}
tran.Commit();
}

xuebim
Follow the latest BIM developments in the architecture industry, explore innovative building technologies, and discover cutting-edge industry insights.
← Scan with WeChat
Like(0) 打赏
BIM WORLD » Revit Secondary Development: How to Quickly Display Hidden Section Boxes

Comment Get first!

Must log in before commenting!

 

BIM World, A Professional BIM Learning Platform

Stay updated on the latest architecture trends and share new building technologies.

Contact UsAbout Us

觉得文章有用就打赏一下小编吧

非常感谢你的打赏,我们将继续提供更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫

微信扫一扫

Account Login

By signing in, you agree toUser Agreement

Sign Up