Filter elements for a linked model

Filter elements for a linked model

adrian_ortega32GAWA
Explorer Explorer
260 Views
1 Reply
Message 1 of 2

Filter elements for a linked model

adrian_ortega32GAWA
Explorer
Explorer

Hey! I'm new to revit;

I've being learning MEP Design, and stumbled upon Clash detections for a personal project, I have a structural model, which's workset is Shared levels and grids. I'm needing to highlight beams and structural elements so that my systems do not clash, but haven't been able to find how to do so. I tried this solution https://forums.autodesk.com/t5/revit-architecture-forum/create-filter-for-linked-revit-file/td-p/104...

 

Thank you in advance, I'm using Revit 2022

0 Likes
Accepted solutions (1)
261 Views
1 Reply
Reply (1)
Message 2 of 2

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @adrian_ortega32GAWA ,

 


1. To filter elements from a linked document, you need to pass the linkedDoc object (of type Document) in the FilteredElementCollector.

2. You can use uidoc.Selection.SetReferences() to highlight elements present in the linked document. I believe this functionality was added in Revit 2023.

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

// Get the first linked Revit document
RevitLinkInstance linkInstance = new FilteredElementCollector(doc).OfClass(typeof(RevitLinkInstance))
    .WhereElementIsNotElementType().FirstElement() as RevitLinkInstance;

Document linkedDoc = linkInstance?.GetLinkDocument();            

// Get all wall elements from the linked document
var walls = new FilteredElementCollector(linkedDoc)
    .OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType();

// Create linked references for selection
var references = walls
    .Cast<Element>()
    .Select(e => new Reference(e).CreateLinkReference(linkInstance)).ToList();

// Highlight the linked wall elements in the UI
uidoc.Selection.SetReferences(references);


3. You can use an intersection filter to determine whether elements in the main document and the linked document intersect. This below sample code works by selecting an element in the linked document
and detecting all elements in the host document it intersects with. (Please note, this sample code is very simple and can be further enhanced and customized by implementing your own logic; This is just for your reference;) 

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

// Get the first Revit link instance in the current document
var linkInst = new FilteredElementCollector(doc)
    .OfClass(typeof(RevitLinkInstance))
    .WhereElementIsNotElementType()
    .FirstOrDefault() as RevitLinkInstance;

 Document linkedDoc = linkInst.GetLinkDocument();

// Let user select one element from the linked model           
Element linkedElement = linkedDoc.GetElement(uidoc.Selection.PickObject(ObjectType.LinkedElement, "Linked").LinkedElementId);

// Extract solid geometry from the linked element
Options geomOptions = new Options { ComputeReferences = true, View = doc.ActiveView, IncludeNonVisibleObjects = true };
Solid linkedSolid = (linkedElement.get_Geometry(geomOptions)?.
    OfType<Solid>().FirstOrDefault());

// Transform linked solid into host document coordinates
Solid transformedSolid = SolidUtils.CreateTransformed(linkedSolid, linkInst.GetTransform());

// Find elements in the main model that intersect with the selected linked element from the linked model.     
var intersectingElements = new FilteredElementCollector(doc)
    .WherePasses(new ElementIntersectsSolidFilter(transformedSolid))
    .WhereElementIsNotElementType();

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes