FilteredElementCollector Class

This class is used to search, filter and iterate through a set of elements.
Inheritance Hierarchy
SystemObject
  Autodesk.Revit.DBFilteredElementCollector

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public class FilteredElementCollector : IEnumerable<Element>, 
	IDisposable

The FilteredElementCollector type exposes the following members.

Constructors
 NameDescription
Public methodFilteredElementCollector(Document) Constructs a new FilteredElementCollector that will search and filter the set of elements in a document.
Public methodCode exampleFilteredElementCollector(Document, ElementId) Constructs a new FilteredElementCollector that will search and filter the visible elements in a view.
Public methodFilteredElementCollector(Document, ICollectionElementId) Constructs a new FilteredElementCollector that will search and filter a specified set of elements.
Public methodFilteredElementCollector(Document, ElementId, ElementId) Constructs a new FilteredElementCollector that will search and filter the visible elements from a Revit link in a host document view.
Top
Properties
 NameDescription
Public propertyIsValidObject Specifies whether the .NET object represents a valid Revit entity.
Top
Methods
 NameDescription
Public methodContainedInDesignOption Applies an ElementDesignOptionFilter to the collector.
Public methodDisposeReleases all resources used by the FilteredElementCollector
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodExcluding Applies an ExclusionFilter to the collector.
Public methodCode exampleFirstElement Returns the first element to pass the filter(s).
Public methodCode exampleFirstElementId Returns the id of the first element to pass the filter(s).
Protected methodGetBasicIEnumeratorReturns an enumerator that iterates through a collection.
Public methodGetElementCount Gets the number of elements in your current filter.
Public methodCode exampleGetElementIdIterator Returns an element id iterator to the elements passing the filters.
Public methodCode exampleGetElementIterator Returns an element iterator to the elements passing the filters.
Public methodGetEnumeratorReturns an enumerator that iterates through a collection.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodIntersectWith Intersects the set of elements passing the filter in this collector with the set of elements passing the filter in another collector.
Public methodStatic memberIsViewValidForElementIteration Identifies if the particular element is valid for iteration of drawn elements.
Public methodCode exampleOfCategory Applies an ElementCategoryFilter to the collector.
Public methodOfCategoryId Applies an ElementCategoryFilter to the collector.
Public methodCode exampleOfClass Applies an ElementClassFilter to the collector.
Public methodOwnedByView Applies an ElementOwnerViewFilter to the collector.
Public methodToElementIds Returns the complete set of element ids that pass the filter(s).
Public methodToElements Returns the complete set of elements that pass the filter(s).
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Public methodUnionWith Unites the set of elements passing the filter in this collector with the set of elements passing the filter in another collector.
Public methodWhereElementIsCurveDriven Applies an ElementIsCurveDrivenFilter to the collector.
Public methodWhereElementIsElementType Applies an ElementIsElementTypeFilter to the collector.
Public methodWhereElementIsNotElementType Applies an inverted ElementIsElementTypeFilter to the collector.
Public methodWhereElementIsViewIndependent Applies an ElementOwnerViewFilter to the collector.
Public methodWherePasses Applies an element filter to the collector.
Top
Remarks

Developers can assign a variety of conditions to filter the elements that are returned. This class requires that at least one condition be set before making the attempt to access the elements.

Revit will attempt to organize the filters in order to minimize expansion of elements regardless of the order in which conditions and filters are applied.

There are three groups of methods that you can use on a given collector once you have applied filter(s) to it. One group provides collections of all passing elements, a second finds the first match of the given filter(s), and a third provides an iterator that is evaluated lazily (each element is tested by the filter only when the iterator reaches it). You should only use one of the methods from these group at a time; the collector will reset if you call another method to extract elements. Thus, if you have previously obtained an iterator, it will be stopped and traverse no more elements if you call another method to extract elements.

In .NET, this class supports the IEnumerable interface for Elements. You can use this class with LINQ queries and operations to process lists of elements. Note that because the ElementFilters and the shortcut methods offered by this class process elements in native code before their managed wrappers are generated, better performance will be obtained by using as many native filters as possible on the collector before attempting to process the results using LINQ queries.

One special consideration when using this class in .NET: the debugger will attempt to traverse the members of the collector because of its implementation of IEnumerable. You may see strange results if you also attempt to extract the first element or all elements from the collector while the debugger is also looking at the contents of the collector.

See Also