LearnRevitAPI

Nov 1, 2024

👉 Advanced Selection

One of the easiest ways to provide a better experience during selection is to limit what can be selected.

And it can be easily achieved by using ISelectionFilter. Let me show you what it is and how to use it.

Here is example on how to allow only furniture selection:

ISelectionFilter

ISelectionFilter Interface provides the ability to filter objects during a selection operation.

💡Interface means that it's a blueprint with certain functionality that you can inherit in your own classes. It might sound confusing to beginners, but it's actually simple to use.

So you would need to:

  • Create your own Class

  • Inherit ISelectionFilter

  • Override Pre-Filter method

  • Provide as argument to Selection methods.

In the documentation we can see what methods that we need to override to make it work.

Selection Methods

If you wonder what methods can take ISelectionFilter you need to look at the arguments in Selection methods.

You will notice that nearly all have this option.

So not, let's look at how to use it

Example #1 - Filter by Class

Here is the first example, where we will allow only Walls to be selected by checking the class.

Here is what's going on:

  • Import UI.Selection classes

  • Create custom filter Class

    • Inherit ISelectionFilter

    • Override AllowElement method

  • Use custom filter in PickObjects

  • Display Results

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 want to filter selection to only walls that have 'beton' in their Type Names.

  • Again I only modified logic in AllowElement Method.

Conclusion

And that's how you can improve user experience during selection.

It definitely looks overwhelming for the first time. But as I said many times : Revit API is very repetitive!

And it's not so hard after you've seen multiple examples. We just need to adjust a few lines of code to make it work for different classes, categories or even read parameters.

Testimonial Highlight

Want to Learn Revit API?

I can help you save months in Learning Revit API by providing a step by step roadmap and everything you might need.
Click here to learn more.

Hundreds of people have already gone through this training and they are automating their boring work in Revit. You can be one of them.

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 7400+ people!