A unique identifier for an Element in an Autodesk Revit project.
Namespace: Autodesk.Revit.DBAssembly: RevitAPI (in RevitAPI.dll) Version: 26.4.0.0 (26.4.0.0)
Syntax
C#
public ElementId Id { get; }Property Value
ElementId
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.
Example
C#
private void CheckElementId(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.Element element)
{
Autodesk.Revit.DB.ElementId selectedId = element.Id;
long idValue = selectedId.Value;
Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(idValue);
Autodesk.Revit.DB.Element first = document.GetElement(id);
Autodesk.Revit.DB.Element second = document.GetElement(selectedId);
String prompt = "Get an element twice. They should be the same element.";
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)
Dim selectedId As Autodesk.Revit.DB.ElementId = element.Id
Dim idValue As Long = selectedId.Value
Dim id As New Autodesk.Revit.DB.ElementId(idValue)
Dim first As Autodesk.Revit.DB.Element = document.GetElement(id)
Dim second As Autodesk.Revit.DB.Element = document.GetElement(selectedId)
Dim prompt As [String] = "Get an element twice. They should be the same element."
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
Reference