Last active
June 14, 2023 08:10
-
-
Save gtalarico/72bd4b6c9fc783c0722397254fbc306a to your computer and use it in GitHub Desktop.
RevitAPI::Code Snippets::Get Selected Elements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uidoc = __revit__.ActiveUIDocument | |
def get_selected_elements(): | |
"""Return Selected Elements as a list[]. Returns empty list if no elements are selected. | |
Usage: | |
- Select 1 or more elements | |
> selected_elements = get_selected_elements() | |
> [<Autodesk.Revit.DB.FamilyInstance object at 0x0000000000000034 [Autodesk.Revit.DB.FamilyInstance]>] | |
""" | |
selection = uidoc.Selection | |
selection_ids = selection.GetElementIds() | |
elements = [] | |
for element_id in selection_ids: | |
elements.append(doc.GetElement(element_id)) | |
return elements | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment