LearnRevitAPI

Dec 26, 2022

Revit API Filters

Using Revit API Filters might look intimidating in the beginning but once you use it a few times you will get a hang of it.

What Filters are available?

FilteredElementCollector (FEC) has a number of methods included for filtering elements by Category, Class, Type...

However, there are additional filters available in the Revit API that have their own classes. These filters can be provided to the FEC using the .WherePasses method.

💡 To get a better understanding of available Filters, open Revit API documentation and search for a word 'filter' with Ctrl+F search. Then scroll through classes.

Many filters are self-explanatory by reading their names but you can always read their description to get better insight.

Filters in the Revit API can be categorized as either quick filters or slow filters, but as a beginner, you should not worry about this. 

The most important thing is to get your scripts working, and you can focus on optimizing their efficiency later if it becomes an issue.

How to use them?

Some filters are easier to work with than others. Read more in Revit API Documentation to understand how to use specific filters.

For example: ElementIsCurveDrivenFilter() does not even need any arguments, we just create an instance of it and pass it to FEC. It will filter elements that use LocationCurve.


Then there are many filters like
ElementLevelFilter(level.Id),
ElementStructuralTypeFilter(StructuralType), 
which take single argument and they are very straight-forward.

👇 ElementLevelFilter - Filter Elements from a specific level.

👇 ElementStructuralTypeFilter - Filter Elements by StructuralType

ElementParameterFilter

ElementParameterFilter(rule) is a very widely used filter, and it might look very complicated at first glance, but I assure you it will make more sense in comparison to Revit UI filters.

I am going to include a page from my PDF guide that will explain ElementParameterFilter pretty well in detail.

Once you start comparing it to Filters in Revit UI, it starts to make more sense.

Filters just follow the rules that we provide. And making a Rule is not complicated. Generally they need:
- Parameter
(ParameterValueProvider)
- Evaluator (FilterStringContains())
- Parameter Value 
and sometimes extra arguments like tolerance, or case-sensitive...

👀 Let's have a look at the real example so you can see it in action.

This snippet will get elements based on Type/Family name. You can easily switch parameter that goes into f_param to decide whether you want Type or Family name parameter.

Logical Filters

Lastly, we can combine various filters together. There are 2 classes:
LogicalAndFilter - All Filters must be matched
LogicalOrFilter    - At least 1 Filter must be matched 

It's similar to And/Or rules in Revit Filters. You either want all condition to be met or meting any of the conditions is enough.

👀 Have a look at more advanced example of using FIlters.
I am going to create 2 ElementParameterFilters and combine them with LogicalAndFilter:

1. Wall Thickness more than 10cm
2. WallType name should contain 'wood' 

⚠️ It will be very hard to learn more about Filters without ever using them. 

Just take some of my examples and try to change them a little.
Take another parameter, modify Evaluator or try to combine multiple filters together.

Get E-Book (20 pages)

In this mini E-Book, you'll learn how to get Revit elements with python using FilteredElementCollector and Revit API Filters. It's a good reference guide to keep on your desk.

👉 Get it Now!

Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7200+ people!

Last Chance To Claim LIFETIME ACCESS. [~40 Seats left]