LearnRevitAPI
🔽Revit API Filters: Quick vs Slow, what's the difference?
Dec 11, 2024
FEC Quick/Slow Filters
If you want to get very specific elements you might need to use Revit API filters. They are a bit confusing at first, and you don't even know what's available.
So let me get you up to speed about 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 'slow' and 'quick' filters?
Does 'slow' mean we shouldn't use those filters? And the answer is - Not at all!
As the name suggests, one type of filter 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 0.0001s longer, so I wouldn't worry unless I do something crazy.
💪 Focus on making them work and leave efficiency for another day.
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, many of these filters have method shortcuts in FEC Class.
💡Method Shortcut means that there is a method in FilteredElementCollector that applies that filter to the collector.
For Example:
.OfClass() method applies ElementClassFilter to the FEC collector. So it's a simple way to use it that makes it quicker and easier for us.
But you could also create it separately and apply by using WherePasses() method.
Slow Filters
Next 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 the Slow Filters have shortcuts in the 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 here.
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?
Now how do we apply filters?
First of all, we need to create them by looking at the constructor method and providing the right arguments if necessary.
Once you have a filter, you can use a method called - WherePasses to apply your filters.
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 the ID of that Symbol in this example:
Conclusion
💡 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.
P.S.
Do you want to learn more about any specific filter?
Let me know.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 7500+ people!