Revit 2025 API Video and Hiding Linked Elements

https://cdn.jsdelivr.net/npm/prismjs@1.29.0/components/prism-core.min.js
https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js
code[class=language-], pre[class=language-] { font-size : 90%; }

The 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:

Revit 2025 API video

Please also refer to the following previous articles related to Revit 2025 API:

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!


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading