ISelectionFilter Example
ISelectionFilter allows you to limit what is allowed to be selected when you use Selection methods.
This might improve user experience by allowing selection of the correct elements for the script. You can define any logic you want for allowing selection.
Simple ISelectionFilter
ISelectionFilter is an Interface. So it means that it is like a blueprint you could use for creating your own class with special functionality.
If you going to check documentation you will notice that ISelectionFilter Interface has 2 methods and it mentions that both needs to be overridden.
Here is a simple example on how to create ISelectionFilter for Wall category.
💡Element argument refers to a placeholder for element. You can use it for creating logical rules that will be applied to all elements in the model to ensure if they can be selected or not
💡If you make any errors inside Interface class you won't see any error messages, it will just return False and disallow selection. So make sure you catch and display your errors with try/except during development. That's very important.
How to use custom ISelectionFilter
Here is how to use this custom filter we created above it for PickObject
Reusable Example
You can also make reusable class for Classes and Categories like this:
You will notice that I added an __init__
to provide a list of allowed types or categories so it can be a reusable class.
Here is an example on how you could use them across all your scripts:
💡As you can see you will provide a list of allowed types/categories and it works.
⌨️ Happy Coding!
Erik Frits