Resources
Summary
Revit API Filters
Welcome to the next module about Revit API Filters.
In this lesson I want to give you a basic overview so you understand what are they all about.
When I talk about Revit API filters, I mean filters that can be applied to FilteredElementCollector for getting our elements. Don’t confuse them with View Filters, which is another topic.
These filters can be divided in 3 categories based on the following classes:
Let’s briefly go through these to understand their differences.
Revit API Quick Filters
Let's start with Quick Filters.
They operate on the ElementRecord. It’s a low-memory class representing element in Revit Database. It has a limited access to read element properties. And as the name suggest they are much quicker than other filters
But let’s be real for a moment.
Most of the times it means that your script will take a fraction of a second instead of a second. And for majority of our script it’s irrelevant difference. Our goal is to make it work, and efficiency start to matter only when it takes too long… So just use whatever works for you!
Since all these filters are based on ElementQuickFilter class, we can look in Inheritance Hierarchy to see all of them.
It might look like a lot of filters, but you already know half of them, since they have shortcut methods in FilteredElementCollector!
For example:
.OfClass() method just applies ElementClassFilter to the collector and if filters has a shortcut just use it instead!
Revit API Slow Filters
Next - Slow Fitlers.
As the name suggest they are less efficient than quick filters, but they have access to more information about elements and therefore we can do more.
They are slow because Elements have to be expanded in memory first to read more about them. But they are not that slow to avoid them! Remember my comparison of script taking 1 second instead of a fraction of a second…
I would also recommend you not to differentiate between quick and slow filters. Just use filters that do what you need, and you will be able to focus on efficiency some other day.
Same as before, all these filters are based on ElementSlowFilter. So we can scroll down to inheritance Hierarchy and get a list of all these filters!
These filters don't have shortcut methods in FilteredElementCollector. But they have a lot of useless filters like AreaFilter, RoomFilter because we can avoid using them by getting elements by Category.
Revit API Logical Filters
Lastly, ElementLogicalFilters.
They are simply used to combine other filters together.
And there are only 2 filters available:
These filters have similar logic as combining view filters.
We either select AND rule, and then all criteria have to meet.
Or we can select OR rule, and then at least one of criteria have to be met.
Extra Tips
Lastly, let me share a few tips it's worth knowing about Filters.
Revit API Filters - Tip 1
Many filters have an option to be reversed.
You will see a boolean argument in FIlter's constructor methods:
This particular filter will get all elements that are not Curve based if you reverse it.
Or let’s say you create a filter to get walls that are higher or equal than 1 meter, and if we apply reverse boolean it will get walls that are lower than 1 meter.
But that depends on the filter if it has this option.
Revit API Filters - Tip 2
Also as you already know many filters have shortcuts in FilteredElementCollector class as methods for easier and quicker use.
For example when we use WhereElementIsElementType() we actually applying ElementIsElementTypeFilter to the collector. When we use OfClass we apply ElementClassFilter and so on...
It's often mentioned in the description of the Filter. But I will list all these filters in the next lesson so you don't have to guess!
Revit API Filters - Tip 3
Lastly, most of the time you are not considering to use Filters, because you don’t even know what filters are available in Revit API. And I was also in this place not knowing what’s available.
The best way to get familiar with them is to open Revit API Documentation, open Autodesk.Revit.DB Namespace and then click on Ctrl + F to activate search function.
Type Filter and you can scroll through documentation.
Or alternatively you can look at Iherentancy Hierarchy of ElementQuickFilter and ElementSlowFilter classes.
HomeWork
So your task after this lesson is to open Revit API Documentation, search for Filter and scroll through the whole database.
Or look at ElementQuickFilter and ElementSlowFilter Inheritance Hierarchy.
Don't spend too much time, just read names of different filters to get familiar with what's available. And we will go through each and every of these filters in the coming lessons
⌨️ Happy Coding!