Element Retrieval

Element Retrieval

Elements in Revit are very common. Retrieving the elements that you want from Revit is necessary before using the API for any Element command. There are several ways to retrieve elements with the Revit API:

Each of these methods of element retrieval is discussed in more details in the following sections.

Getting an Element by ID

When the ElementId of the desired element is known, use the Document.Element property to get the element.

Filtering the Elements Collection

The most common way to get elements in the document is to use filtering to retrieve a collection of elements. The Revit API provides the FilteredElementCollector class, and supporting classes, to create filtered collections of element which can then be iterated. See Filtering for more information.

Selection

Rather than getting a filtered collection of all of the elements in the model, you can access just the elements that have been selected. You can get the selected objects from the current active document using the UIDocument.Selection.GetElementIds method. For more information on using the active selection, see Selection.

Accessing Specific Elements from Document

In addition to using the general way to access Elements, the Revit Platform API has properties in the Document class to get the specified Elements from the current active document without iterating all Elements. The specified Elements you can retrieve are listed in the following table.

Table 11: Retrieving Elements from document properties

Element

Access in property of Document

ProjectInfo

Document.ProjectInformation

ProjectLocation

Document.ProjectLocations

Document.ActiveProjectLocation

SiteLocation

Document.SiteLocation

Phase

Document.Phases