selection
Elements selection utilities.
Attributes
mlogger = get_logger(__name__)
module-attribute
Classes
ElementSelection(element_list=None)
Element selection handler.
Host elements are tracked as ElementIds of the active document.
Elements inside linked models are tracked separately as host-context link
references (see link_references and linked_elements), because their ids
belong to the link document and must never be resolved against the host.
Note
Iteration, indexing, elements, element_ids, first, last,
include, exclude and expand_groups only cover host elements.
__len__ and is_empty cover both host and linked entries.
When created without arguments, only the host part of the current
Revit selection is read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_list
|
list[Element]
|
list of selected elements |
None
|
Source code in pyrevitlib/pyrevit/revit/selection.py
Attributes
is_empty
property
elements
property
element_ids
property
link_references
property
list[DB.Reference]: host-context references to the linked elements.
Each reference points at the link instance (ElementId) and at the
element inside the link document (LinkedElementId).
linked_elements
property
list[DB.Element]: selected elements that live in linked documents.
Entries whose link instance was deleted or whose link was unloaded since selection, or whose element no longer exists, are skipped.
first
property
last
property
Methods:
get_element_ids(mixed_list)
classmethod
set_to(element_list)
Replace the Revit selection with the given items.
Accepts host elements, element ids, elements from linked documents
(e.g. from pick_linkeds) and DB.Reference objects, in any mix.
Linked elements end up individually selected, as if Tab-selected into
the link. None entries and a None list are ignored.
Note
A bare linked element carries no link instance, so the first loaded
instance of its link document is used. Pass the picked
DB.Reference objects instead to target a specific instance when
the same file is linked more than once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_list
|
list | object | None
|
items to select. |
required |
Raises:
| Type | Description |
|---|---|
PyRevitException
|
If linked elements are given on Revit 2022 or older, which cannot select elements inside links. The selection is left unchanged in that case. |
Source code in pyrevitlib/pyrevit/revit/selection.py
clear()
append(element_list)
include(element_type)
exclude(element_type)
no_views()
only_views()
expand_groups()
Source code in pyrevitlib/pyrevit/revit/selection.py
PickByCategorySelectionFilter(category_id)
Bases: ISelectionFilter
Source code in pyrevitlib/pyrevit/revit/selection.py
Attributes
category_id = category_id
instance-attribute
Methods:
AllowElement(element)
Functions:
pick_element(message='', pick_filter=None)
Asks the user to pick an element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message to display. |
''
|
pick_filter
|
object
|
An object specifying the filter to apply when picking elements. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
Element
|
element selected by the user. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_element_by_category(cat_name_or_builtin, message='')
Returns the element of the specified category picked by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_name_or_builtin
|
str
|
name or built-in category of the element to pick. |
required |
message
|
str
|
message to display on selection. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
Element
|
picked element. |
Raises:
| Type | Description |
|---|---|
PyRevitException
|
If no category matches the specified name or builtin. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elementpoint(message='', world=False)
Returns the element point selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
world
|
bool
|
whether to use world coordinates. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
PointOnElement
|
The selected point. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_edge(message='')
Returns the edge selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
Edge
|
The selected edge. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_face(message='')
Returns the face selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
Face
|
The selected face. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_linked(message='', pick_filter=None)
Returns the linked element selected by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
message to display. Defaults to ''. |
''
|
pick_filter
|
object
|
An object specifying the filter to apply when picking elements. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
LinkedElement
|
The selected linked element. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elements(message='', pick_filter=None)
Asks the user to pick multiple elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
An optional message to display. |
''
|
pick_filter
|
object
|
An object specifying the filter to apply when picking elements. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
list[Element]
|
elements selected by the user. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elements_by_category(cat_name_or_builtin, message='')
Returns the elements of the specified category picked by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_name_or_builtin
|
str
|
name or built-in category of the elements to pick. |
required |
message
|
str
|
message to display on selection. Defaults to ''. |
''
|
Returns:
| Type | Description |
|---|---|
list[Element]
|
picked elements. |
Raises:
| Type | Description |
|---|---|
PyRevitException
|
If no category matches the specified name or builtin. |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_picked_elements(message='')
Allows the user to pick multple elements, one at a time.
It keeps asking the user to pick an element until no elements are selected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display. Defaults to ''. |
''
|
Yields:
| Type | Description |
|---|---|
Element
|
selected element |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_picked_elements_by_category(cat_name_or_builtin, message='')
Pick elements by category.
Keeps asking the user to pick an element until no elements are selected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cat_name_or_builtin
|
str
|
category name or built-in category. |
required |
message
|
str
|
message to display while picking elements. |
''
|
Yields:
| Type | Description |
|---|---|
Element
|
The picked elements from the specified category. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_elementpoints(message='', world=False)
Selects element points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting element points. |
''
|
world
|
bool
|
Select points in world coordinates. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
list[PointOnElement]
|
selected element points. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_edges(message='')
Selects edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting edges. |
''
|
Returns:
| Type | Description |
|---|---|
list[Edge]
|
selected edges. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_faces(message='')
Selects faces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting the faces. |
''
|
Returns:
| Type | Description |
|---|---|
list[Face]
|
selected faces. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_linkeds(message='', pick_filter=None)
Selects linked elements.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The message to display when selecting linked elements. Default is an empty string. |
''
|
pick_filter
|
object
|
An object specifying the filter to apply when picking elements. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
list[LinkedElement]
|
selected linked elements. |
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_point(message='')
Pick a point from the user interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
A message to display when prompting for the point. |
''
|
Returns:
| Type | Description |
|---|---|
tuple or None
|
A tuple representing the picked point as (x, y, z) coordinates, or None if no point was picked or an error occurred. |
Side Effects
If the active view does not have a SketchPlane assigned, this
function will automatically create a temporary work plane (aligned with the
active view) and assign it to the view before prompting for the point.
The work plane is removed after picking to avoid modifying the document.
Source code in pyrevitlib/pyrevit/revit/selection.py
pick_rectangle(message='', pick_filter=None)
Picks elements from the user interface by specifying a rectangular area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
A custom message to display when prompting the user to pick elements. Default is an empty string. |
''
|
pick_filter
|
object
|
An object specifying the filter to apply when picking elements. Default is None. |
None
|
Returns:
| Type | Description |
|---|---|
list[ElementId]
|
The selected elements. |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_selection_category_set()
Returns a CategorySet with the categories of the selected elements.
Returns:
| Type | Description |
|---|---|
CategorySet
|
categories of the selected elements. |
Source code in pyrevitlib/pyrevit/revit/selection.py
get_selection()
Returns the current selected items.
Returns:
| Type | Description |
|---|---|
ElementSelection
|
the current selected items |