A unique identifier for an Element in an Autodesk Revit project.
Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 26.1.0.0 (26.1.0.34)
Syntax
C#
public ElementId Id { get; }
Property Value
ElementIdRemarks
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.Example
C#
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); }
VB
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