Share

ElementCategoryFilter Class

A filter used to match elements by their category.

Inheritance Hierarchy

System.Object
  Autodesk.Revit.DB.ElementFilter
    Autodesk.Revit.DB.ElementQuickFilter
      Autodesk.Revit.DB.ElementCategoryFilter


Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.3.0.0 (25.3.0.0)

Syntax

C#

public class ElementCategoryFilter : ElementQuickFilter

The ElementCategoryFilter type exposes the following members.

Constructors

 NameDescription
Public methodElementCategoryFilter(BuiltInCategory) Constructs a new instance of a filter to match elements by category.
Public methodElementCategoryFilter(ElementId) Constructs a new instance of a filter to match elements by category.
Public methodElementCategoryFilter(BuiltInCategory, Boolean) Constructs a new instance of a filter to match elements by category, with the option to match all elements which are not of the given category.
Public methodElementCategoryFilter(ElementId, Boolean) Constructs a new instance of a filter to match elements by category, with the option to match all elements which are of the given category.

Properties

 NameDescription
Public propertyCategoryId The category id.
Public propertyInverted True if the results of the filter are inverted; elements that would normally be accepted by this filter will be rejected, and elements that would normally be rejected will be accepted.
(Inherited from ElementFilter)
Public propertyIsValidObject Specifies whether the .NET object represents a valid Revit entity.
(Inherited from ElementFilter)

Methods

 NameDescription
Public methodDispose
(Inherited from ElementFilter)
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodPassesFilter(Element) Applies the filter to a given element.
(Inherited from ElementFilter)
Public methodPassesFilter(Document, ElementId) Applies the filter to a given element.
(Inherited from ElementFilter)
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)

Remarks

This filter is a quick filter. Quick filters operate only on the ElementRecord, a low-memory class which has a limited interface to read element properties. Elements which are rejected by a quick filter will not be expanded in memory.

Example

C#

// 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);

VB

' Find all Wall instances in the document by using category filter
Dim filter As New ElementCategoryFilter(BuiltInCategory.OST_Walls)

' Apply the filter to the elements in the active document,
' Use shortcut WhereElementIsNotElementType() to find wall instances only
Dim collector As New FilteredElementCollector(document)
Dim walls As IList(Of Element) = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements()
Dim prompt As [String] = "The walls in the current document are:" & vbLf
For Each e As Element In walls
   prompt += e.Name + vbLf
Next
TaskDialog.Show("Revit", prompt)

See Also

Reference

Was this information helpful?