The Revit API provides a mechanism for filtering and iterating elements in a Revit document. This is the best way to get a set of related elements, such as all walls or doors in the document. Filters can also be used to find a very specific set of elements, such as all beams of a specific size.
The basic steps to get elements passing a specified filter are as follows:
The following sample covers the basic steps to filtering and iterating elements in the document.
Code Region 6-1: Use element filtering to get all wall instances in document |
// Find all Wall instances in the document by using category filter ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls); // Apply the filter to the elements in the active document // Use shortcut WhereElementIsNotElementType() to find wall instances only FilteredElementCollector collector = new FilteredElementCollector(document); IList<Element> walls = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements(); String prompt = "The walls in the current document are:\n"; foreach (Element e in walls) { prompt += e.Name + "\n"; } TaskDialog.Show("Revit", prompt); |