Id Property


A unique identifier for an Element in an Autodesk Revit project.

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

Syntax

C#
public ElementId Id { get; }
Visual Basic
Public ReadOnly Property Id As ElementId
	Get
Visual C++
public:
property ElementId^ Id {
	ElementId^ get ();
}

Remarks

Returns an object containing the project-wide unique identifier for this Element. The identifier with this id is only unique for the project, it is not unique across separate Autodesk Revit projects.

Examples

CopyC#
private void CheckElementId(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element)
{
    // Get the id of the element
    Autodesk.Revit.DB.ElementId selectedId = element.Id;
    long idValue = selectedId.Value;

    // create a new id and set the value
    Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(idValue);

    // Get the element 
    Autodesk.Revit.DB.Element first = document.GetElement(id);

    // And get the element using the original Id (they should be the same)
    Autodesk.Revit.DB.Element second = document.GetElement(selectedId);

    String prompt = "Get an element twice. They should be the same element.";
    // Use the Equal method to check two elements. It is not a good way.
    bool isSame = first.Equals(second);
    prompt += "\nUsing Equal method on elements, the result is: " + isSame;
    isSame = first.Id.Equals(second.Id);
    prompt += "\nUsing Equal method on element's Id properties, the result is: " + isSame;

    TaskDialog.Show("Revit",prompt);
}
CopyVB.NET
Private Sub CheckElementId(document As Autodesk.Revit.DB.Document, element As Autodesk.Revit.DB.Element)
    ' Get the id of the element
    Dim selectedId As Autodesk.Revit.DB.ElementId = element.Id
    Dim idValue As Long = selectedId.Value

    ' create a new id and set the value
    Dim id As New Autodesk.Revit.DB.ElementId(idValue)

    ' Get the element 
    Dim first As Autodesk.Revit.DB.Element = document.GetElement(id)

    ' And get the element using the original Id (they should be the same)
    Dim second As Autodesk.Revit.DB.Element = document.GetElement(selectedId)

    Dim prompt As [String] = "Get an element twice. They should be the same element."
    ' Use the Equal method to check two elements. It is not a good way.
    Dim isSame As Boolean = first.Equals(second)
    prompt += vbLf & "Using Equal method on elements, the result is: " & isSame
    isSame = first.Id.Equals(second.Id)
    prompt += vbLf & "Using Equal method on element's Id properties, the result is: " & isSame

    TaskDialog.Show("Revit", prompt)
End Sub

See Also

ArchiLabs

Stop fighting Revit automation.

Build repeatable BIM design and documentation workflows with scripts, data, and AI in one place, without wrestling brittle one-off automations.

Try ArchiLabs →