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 Element object, or null 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 a single element

  • Restores the original selection after the operation completes

  • Returns null if 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 Element object if it belongs to the specified category, or null if the selection was canceled, failed, or the selected element is not of the specified category.

Behavior:

  • Uses SelectElement method to get a user selection

  • Verifies that the selected element belongs to the specified category

  • Shows an error message if the selected element is not of the correct category

  • Returns null if 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 Launchpad

  • promptMessage: 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, or null if no elements of the specified category were selected.

Behavior:

  • Uses SelectElements method to get multiple user selections

  • Filters the selections to only include elements of the specified category

  • Shows an error message if no elements of the specified category were selected

  • Returns null if no elements of the correct category were found

Last updated