LearnRevitAPI
![](https://framerusercontent.com/images/zMFB840Y52OLteloUT4BRuogE.png)
![](https://framerusercontent.com/images/U9zjOvD4k3m6cIJd5bOiu960DeI.png)
Jan 10, 2023
Select/Pick Elements
![](https://framerusercontent.com/images/Sd5FTaxiqzG7oeH1ykV6yypUzXo.png?scale-down-to=512)
Selection and Picking is often a good way for a user to provide a useful input for your custom tools. So let me break it down for you and give a few examples that you can start using today.
Selection Class
There is a Selection Class in Revit API which allows us to get user selection or activate picking tools. It is located in Autodesk.Revit.UI.Selection Namespace.
Getting Selection instance is very easy, since uidoc has a property for that. Have a look at the images below to see how to get Selection instance and what methods are available.
![](https://framerusercontent.com/images/5guFOm39RliWB1puhEKNe5Hgsbs.png)
Selection Class
You can read more about each method available in Revit API Documentation.
![](https://framerusercontent.com/images/A8NEo7jf6E8JHZygulbHJK2aM.png)
Imports & Variables
Imports and Variables that I will be using for my examples.
Get Selected Elements
Let's start by getting user's selection. There is a self-explaining method called .GetElementIds() so it's going to be very simple. Have a look at the snippet
👇
![](https://framerusercontent.com/images/DsSvf1ptK0SVdhWt69wdH8qk.png)
Set Selection
Setting selection is also easy. You just need provide a List[ElementId]() for new selection in .SetElementIds() method.
👇
![](https://framerusercontent.com/images/c8KpOO1VbEXcEkjpkQR5JUZO4.png)
Pick Elements
Picking is also a great way for a user to provide input. There are multiple methods available to pick your elements .
PickObject - Pick a single element
PickObjects - Pick multiple Elements and confirm your selection
PickElementsByRectangle - Select Elements with a rectangle
Notice in Revit API Documentation that:
PickObject/s return Reference
PickElementByRectangle returns List[Elements]
So we need to convert Reference into Elements by using doc.GetElement()
![](https://framerusercontent.com/images/wFOLKyP5rwLGp5kPwgGhEawVoJg.png)
You might have noticed that one of the arguments is ObjectType.
It's an enumeration that contains the following options: [Nothing, Element, PointOnElement, Edge, Face, LinkedElement, Subelement ]
Pick Position
We can also ask user to provide a location input such as Point or PickBox. There are 2 methods in Selection class that can help us out:
- PickPoint() - Return XYZ Point
- PickBox() - Return selected PickBox (You can extract .Min and .Max points )
![](https://framerusercontent.com/images/rLB3aUnt9rUvgFJHq4yGc4J2tj0.png)
ISelectionFilter
Lastly, If you look through these methods you might notice an argument: ISelectionFilter. It allows us to filter elements that user is allowed to select.
![](https://framerusercontent.com/images/4cERJdq2crBUftPzsrwgwFVp9nA.png)
ISelectionFilter is an interface in Revit API to create our custom subclasses with rules for selection.
There are 2 methods that we can override:
- AllowElement(element)
- AllowReference(reference, position)
We can make any logical checks we want by using argument - element.
In the example below I've created ISelectionFilter that will make sure that only elements with allowed type will be selected, and then I passed it to PickObjects method.
Then I created an instance of my filter to filter Walls, Floors, Roofs and Ceilings. When PickObjects will be run, user will only be able to select these types of elements.
![](https://framerusercontent.com/images/8aAfzTXlRUDpmTmHRO7sBIFHUDw.png)
I hope you learnt something new about Selection. And if you have trouble with any of the snippet I provided, reach out and let me know. I will try to help you.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 6700+ people!
![](https://framerusercontent.com/images/svHzzMLtnnRCxtCUwbgAm6CUeB8.jpg)
![](https://framerusercontent.com/images/Y44kwhY0i7q37LzXUjrlxeGUo.jpg)
![](https://framerusercontent.com/images/lqKYmh8rqwZwgY2C9MSQER6iBCI.jpg)
![](https://framerusercontent.com/images/SyGCvJ3dbHsJEyklWWBhweY.jpg)
![](https://framerusercontent.com/images/DwiaUdmQHs3FVdDH2PXwAr0Y.jpg)