Revit 2025 API Video and Hiding Linked Elements
Originally Published inThe video recording on what’s new in the Revit 2025 API has been released, and we discuss a nice example combining element pre-selection and PostCommand
:
Revit 2025 API Video
Boris Shafiro and Michael Morris present the video recording of the presentations on What’s new in Autodesk Revit 2025 API ↗. It consists of three parts:
- Introduction and .NET 8 Migration ↗ (7 minutes)
- Breaking changes and removed API ↗ (15 minutes)
- New APIs and Capabilities ↗ (40 minutes)
Please also refer to the following previous articles related to Revit 2025 API:
- Revit 2025 and RevitLookup 2025 ↗
- The Building Coder Samples 2025 ↗
- RevitLookup Hotfix and the Revit 2025 SDK ↗
- What’s New in the Revit 2025 API ↗
- Migrating VB to .NET Core 8 ↗
- Revit 2025.1 ↗
Hiding Linked Elements
Turning to a topic that has not yet been addressed by the new release, the open Revit Ideas wish list item to hide elements in linked model ↗, Lorenzo Virone shared a solution using PostCommand
and element pre-selection via Selection.SetReferences
. He explains the detailed approach in the Revit API discussion forum ↗ thread on how to hide elements in linked file ↗:
This solution also demonstrates how to preselect elements for PostCommand
processing:
// Select elements using UIDocument
// then use PostCommand "HideElements"
// elemsFromRevitLinkInstance is "List<Element>"
// these are the elements you want to hide in the link
var refs = elemsFromRevitLinkInstance.Select( x
=> new Reference(x).CreateLinkReference(revitLinkInstance))
.ToList();
uidoc.Selection.SetReferences(refs);
uidoc.Application.PostCommand(
RevitCommandId.LookupPostableCommandId(
PostableCommand.HideElements));
Response: Can you provide a description of the process for using your code to hide elements only in a linked model? I am not familiar with the API and deploying a script like this.
Answer: Here is an sample that selects the first RevitLinkInstance, retrieve its floors and hides them:
// Get a link
var filter = new ElementClassFilter(typeof(RevitLinkInstance));
var firstInstanceLink
= (RevitLinkInstance) new FilteredElementCollector(doc)
.WherePasses(filter)
.FirstElement();
// Get its floors
filter = new ElementClassFilter(typeof(Floor));
var elemsFromRevitLinkInstance
= new FilteredElementCollector(
firstInstanceLink.GetLinkDocument())
.WherePasses(filter)
.ToElements();
// Isolate them
var refs = elemsFromRevitLinkInstance.Select( x
=> new Reference(x).CreateLinkReference(firstInstanceLink))
.ToList();
uidoc.Selection.SetReferences(refs);
uidoc.Application.PostCommand(
RevitCommandId.LookupPostableCommandId(
PostableCommand.HideElements));
Many thanks to Lorenzo for addressing this need and sharing his helpful solution!