Skip to content

FilteredElementCollector

Public Class

This class is used to search, filter and iterate through a set of elements.

Inheritance Hierarchy

System.Object
Autodesk.Revit.DB.FilteredElementCollector

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

Name

Description


Public Method
FilteredElementCollector(Document)

Constructs a new FilteredElementCollector that will search and filter the set of elements in a document.


Public Method
Code Example
FilteredElementCollector(Document, ElementId)

Constructs a new FilteredElementCollector that will search and filter the visible elements in a view.


Public Method
FilteredElementCollector(Document, ICollection.ElementId.)

Constructs a new FilteredElementCollector that will search and filter a specified set of elements.


Public Method
FilteredElementCollector(Document, ElementId, ElementId)

Constructs a new FilteredElementCollector that will search and filter the visible elements from a Revit link in a host document view.


Properties

Name

Description


Public Property
IsValidObject

Specifies whether the .NET object represents a valid Revit entity.


Methods

Name

Description


Public Method
ContainedInDesignOption

Applies an ElementDesignOptionFilter to the collector.


Public Method

Releases all resources used by the FilteredElementCollector


Public Method

Equals

Determines whether the specified object is equal to the current object.
(Inherited from Object)


Public Method
Excluding

Applies an ExclusionFilter to the collector.


Public Method
Code Example
FirstElement

Returns the first element to pass the filter(s).


Public Method
Code Example
FirstElementId

Returns the id of the first element to pass the filter(s).


Protected Method

Returns an enumerator that iterates through a collection.


Public Method
GetElementCount

Gets the number of elements in your current filter.


Public Method
Code Example
GetElementIdIterator

Returns an element id iterator to the elements passing the filters.


Public Method
Code Example
GetElementIterator

Returns an element iterator to the elements passing the filters.


Public Method

Returns an enumerator that iterates through a collection.


Public Method

GetHashCode

Serves as the default hash function.
(Inherited from Object)


Public Method

GetType

Gets the Type of the current instance.
(Inherited from Object)


Public Method
IntersectWith

Intersects the set of elements passing the filter in this collector with the set of elements passing the filter in another collector.


Public Method
Static Member
IsViewValidForElementIteration

Identifies if the particular element is valid for iteration of drawn elements.


Public Method
Code Example
OfCategory

Applies an ElementCategoryFilter to the collector.


Public Method
OfCategoryId

Applies an ElementCategoryFilter to the collector.


Public Method
Code Example
OfClass

Applies an ElementClassFilter to the collector.


Public Method
OwnedByView

Applies an ElementOwnerViewFilter to the collector.


Public Method
ToElementIds

Returns the complete set of element ids that pass the filter(s).


Public Method
ToElements

Returns the complete set of elements that pass the filter(s).


Public Method

ToString

Returns a string that represents the current object.
(Inherited from Object)


Public Method
UnionWith

Unites the set of elements passing the filter in this collector with the set of elements passing the filter in another collector.


Public Method
WhereElementIsCurveDriven

Applies an ElementIsCurveDrivenFilter to the collector.


Public Method
WhereElementIsElementType

Applies an ElementIsElementTypeFilter to the collector.


Public Method
WhereElementIsNotElementType

Applies an inverted ElementIsElementTypeFilter to the collector.


Public Method
WhereElementIsViewIndependent

Applies an ElementOwnerViewFilter to the collector.


Public Method
WherePasses

Applies an element filter to the collector.


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.