LearnRevitAPI
Dec 29, 2024
Revit API Filters
If you've worked with the Revit API for a while, you've probably come across Revit API Filters.
They might seem tough at first, but they're not too hard to use. The main challenge is figuring out which filters are available in the Revit API.
Even I found some new filters myself not long ago...
💡So Let's look at all filters in Revit API
Filter Types
When I talk about Revit API filters, I mean filters that can be applied to FilteredElementCollector for get elements.
Don’t confuse them with View Filters, which is another topic.
Generally, there are 3 types of filters in Revit API:
Let's briefly explore each of them to understand how they work.
Slow vs Quick Filters?
You might be wondering why there are both 'slow' and 'quick' filters.
Does 'slow' mean we shouldn't use those filters?
And the answer is - Not at all!
As the name suggest one type of filters is quicker than the other.
Quick filters work faster because they look at a database record. They don't need to know every detail about the elements to filter them
On the other hand, slow filters need more information about each element. That means they have to load all the details of the elements into memory to check their different properties.
❗But you shouldn't even worry about this difference.
Most of the time, this just means your script will take a tiny bit longer - like a fraction of a second instead of one second.
For most of our scripts, this small difference doesn't matter. The main thing is to make it work. Worrying about speed only matters if it's really slow.
💪 So just use whatever works for you!
Quick FIlters
All quick filters are based on ElementQuickFilter Class.
This means you can scroll down to Inheritance Hierarchy to see all of them.
I would recommend scrolling through the list and read their names. They are quite self-explanatory.
Also, almost half of these filters have shortcuts in the methods of FilteredElementCollector.
💡 Shortcut means that there is a method in FilteredElementCollector that applies that filter to the collector.
For Example:
.OfClass() method applies ElementClassFilter to the collectorSo, if a filter has a shortcut like this, just use it. It makes things easier!
Slow Filters
Just like quick filters, all slow filters are based on ElementSlowFilter class. So you can scroll down to inheritance Hierarchy and get a list of all these filters!
💡None of Slow Filters have shortcuts in FEC class. However, there are many interesting filters to explore.
Especially ElementParameterFilter and ElementIntersectsFilter. These are not as simple to use, but they are really powerful!
I've recently created a detailed video about ElementParameterFilters. You can watch it by clicking on this thumbnail:
Logical Filters
Lastly, there are just 2 logical filters:
- LogicalAndFilter
- LogicalOrFilter
These filters combine other filters using AND/OR logic. When applied to a collector, either all filters must be true (AND logic) or at least one (OR logic) to select your elements.
How to Apply Filters?
FilteredElementCollector has a method called WherePasses, which takes your Filter as an argument.
To create a filter you would need to look in Filter's Constructors.
Let's start simple and look at - ElementIsCurveDrivenFilter
This filter requires no arguments, so you simply call it to create and apply the collector.
Other filters might have more arguments to create them.
For example - FamilySymbolFilter
This filter needs Family Id as an argument.
I will manually write Id of that Family in this example:
💡 Generally, most filters are quite straightforward to use.
The key is knowing if there's a filter that can help you find the right elements. Once you know that, you will figure out how to use it.
So, I would encourage you to scroll through the list of filters to better understand them.
Resources
I recently discovered the Revit API Developer's Guide by Autodesk.
It has an nice page about all these filters, which I highly recommend for a deeper understanding.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7400+ people!
◼️BLACK FRIDAY DEAL 20% OFF. Ends in: