Element Selection Methods
Use these methods to prompt the user to select an element or elements in Revit
Select Element
Prompts the user to select a single element from the Revit model.
public Element SelectElement(UIDocument uidoc, string promptMessage = "Select an element:")Parameters:
uidoc: The Revit UI document.promptMessage: Optional. Message to display to the user when selecting. Default is "Select an element:".
Returns:
The selected
Elementobject, ornullif the selection was canceled or failed.
Behavior:
Shows a task dialog with the provided prompt message
Stores the current selection to restore it after the operation
Allows the user to select a single element
Restores the original selection after the operation completes
Returns
nullif the user cancels the selection or an error occurs
SelectElementByCategory
Prompts the user to select a single element of a specific category from the Revit model.
Parameters:
uidoc: The Revit UI document.categoryName: The name of the category to filter by.promptMessage: Optional. Message to display to the user when selecting. Default is "Select an element:".
Returns:
The selected
Elementobject if it belongs to the specified category, ornullif the selection was canceled, failed, or the selected element is not of the specified category.
Behavior:
Uses
SelectElementmethod to get a user selectionVerifies that the selected element belongs to the specified category
Shows an error message if the selected element is not of the correct category
Returns
nullif the selection was canceled or the element is of the wrong category
SelectElements
Prompts the user to select multiple elements from the Revit model using a rectangle selection.
Parameters:
uidoc: The Revit UI document. Use uidoc in LaunchpadpromptMessage: Optional. Message to display to the user when selecting. Default is "Select elements:".
Returns:
A
List<Element>containing the selected elements, or an empty list if the selection was canceled or failed.
Behavior:
Shows a task dialog with the provided prompt message
Stores the current selection to restore it after the operation
Allows the user to select multiple elements by drawing a rectangle
Restores the original selection after the operation completes
Returns selected elements even if the user cancels during multi-selection
Returns an empty list if no elements were selected or an error occurs
SelectElementsByCategory
Prompts the user to select multiple elements of a specific category from the Revit model.
Parameters:
uidoc: The Revit UI document.categoryName: The name of the category to filter by.promptMessage: Optional. Message to display to the user when selecting. Default is "Select elements:".
Returns:
A
List<Element>containing the selected elements that belong to the specified category, ornullif no elements of the specified category were selected.
Behavior:
Uses
SelectElementsmethod to get multiple user selectionsFilters the selections to only include elements of the specified category
Shows an error message if no elements of the specified category were selected
Returns
nullif no elements of the correct category were found
Last updated