LearnRevitAPI

👉 How To Prevent Revit Users from Selecting the Wrong Elements

Jul 30, 2025
Advanced Selection

Selection is not hard in Revit API.
However, users like to break our Revit tools... And we can avoid that by limiting what can be selected. This way users can only select the right elements and ensure everything works correctly.
For that we need to use ISelectionFilter Interface.
So let me break it down for you.
It's time to limit what can be selected.

Advanced Selection in Revit API
In the previous newsletter you've learnt the basics on how to select elements with Revit API.
That's already a great start but it can lead to situations where users select wrong elements. That can confuse users and even break your code if you didn't think of that.
So instead, we can take it to the next level by adding custom filters on what's allowed to be selected. This will provide a far better user experience.
For example, imagine that you need users to only select furniture. We can limit selection and then no matter how hard they try, only furniture will be selected:

As you can see, only furniture can be selected.
To add these custom filter rules during selection we need to use ISelectionFilter. It's provided as one of the arguments to selection methods.

What is ISelectionFilter ?
ISelectionFilter Interface provides the ability to add filtering rules during selection. This is how you limit what's allowed and what's not.
💡Interface in programming is a blueprint for creating your own classes with certain functionality included. It might sound confusing, but it will get simple once you see an example.
In short you need to:
Create custom class based on ISelectionFilter
Override AllowElement method
Provide it as an argument for Selection methods.
So the main goal is to override AllowElement method when you create you own filter class based on ISelectionFilter

Let's dive into examples and it will get clear.
Example #1 - Filter by Class
Here is the first example, where we will allow only Walls to be selected by checking element types.

Here is what's going on:
Import UI.Selection classes
Create custom filter Class
Inherit ISelectionFilter
Override AllowElement method
Apply in PickObjects method
And here's the result:

Notice that when we hover over all elements, only walls are being selected. That's the advanced technique in action.
The idea is to create logic in AllowElement method that returns True to elements which are allowed to be selected.
Example #2 - By Category
Here is another example, but this time I want to filter based on Category. Let's limit selection to OST_Furniture.

Everything is the same as before.
I've only changed the logic in AllowElement method.

💡Keep in mind that Category.BuiltInCategory is only available from Revit 2022+. So it's better to use Category.Id to find the match.
Example #3 - 'Beton' in type name
Let's make it more interesting.
I only want to select Walls that have 'beton' in their Type Name. So here is the code to do that:

Again, I only modified logic in AllowElement Method.
The rest stays the same...

Conclusion
That's how we can improve user experience during selection.
ISelectionFilter might sounded confusing at first, but then you realize that you copy the same template and only modify code inside AllowElement Method.
This makes it easy even for absolute beginners.
So give it a try!
💡Remember, Revit API is very repetitive, and once you see how something works, it becomes very easy to reuse it again.
I try my best to provide you the most useful code examples so you can apply it in your own code ASAP. So please, use it.
P.S.
Code is the greatest leverage for your time!

Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 9500+ people!




