GetElement

T? GetElement<T>(this Document doc, ElementId id) where T : Element

Gets an element by id and casts it to the specified type T. Returns null if not found or type mismatch.

Parameters

  • docDocument

    The Revit document instance.

  • idElementId

    The id of the element to retrieve.

Returns: The element cast to T if found and compatible; otherwise null.

Example

ElementId wallId = new ElementId(12345);
Wall? wall = doc.GetElement<Wall>(wallId);
if (wall != null)
{
TaskDialog.Show("Wall", wall.Name);
}