RVTDocs.com
Namespace: Autodesk.Revit.DB Class: Element

Element.Id

Property
Description:
A unique identifier for an Element in an Autodesk Revit project.
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.
Syntax
public ElementId Id { get; }
Examples
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);
}