GetElementIdIterator Method


Returns an element id iterator to the elements passing the filters.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 24.0.0.0 (24.0.0.0)
Since:  2011

Syntax

C#
public FilteredElementIdIterator GetElementIdIterator()
Visual Basic
Public Function GetElementIdIterator As FilteredElementIdIterator
Visual C++
public:
FilteredElementIdIterator^ GetElementIdIterator()

Remarks

Calling this when you have an active iterator to this same collector will result in the first iterator being stopped by this call.

Examples

CopyC#
// Use a RoomFilter to find all room elements in the document. 
RoomFilter filter = new RoomFilter();

// Apply the filter to the elements in the active document
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.WherePasses(filter);

// Get results as ElementId iterator
FilteredElementIdIterator roomIdItr = collector.GetElementIdIterator();
roomIdItr.Reset();
while (roomIdItr.MoveNext())
{
    ElementId roomId = roomIdItr.Current;
    // Warn rooms smaller than 50 SF
    Room room = document.GetElement(roomId) as Room;
    if (room.Area < 50.0)
    {
        String prompt = "Room is too small: id = " + roomId.ToString();
        TaskDialog.Show("Revit", prompt);
        break;
    }
}
CopyVB.NET
' Use a RoomFilter to find all room elements in the document. 
Dim filter As New RoomFilter()

' Apply the filter to the elements in the active document
Dim collector As New FilteredElementCollector(document)
collector.WherePasses(filter)

' Get results as ElementId iterator
Dim roomIdItr As FilteredElementIdIterator = collector.GetElementIdIterator()
roomIdItr.Reset()
While roomIdItr.MoveNext()
   Dim roomId As ElementId = roomIdItr.Current
   ' Warn rooms smaller than 50 SF
   Dim room As Room = TryCast(document.GetElement(roomId), Room)
   If room.Area < 50.0 Then
      Dim prompt As [String] = "Room is too small: id = " & roomId.ToString()
      TaskDialog.Show("Revit", prompt)
      Exit While
   End If
End While

Exceptions

ExceptionCondition
Autodesk.Revit.ExceptionsInvalidOperationException The collector does not have a filter applied. Extraction or iteration of elements is not permitted without a filter.

See Also

ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →