The following properties are common to each Element created using Revit.
Every element in an active document has a unique identifier represented by the ElementId storage type. ElementId objects are project wide. It is a unique number that is never changed in the element model, which allows it to be stored externally to retrieve the element when needed.
To view an element ID in Revit, complete the following steps:
Select IDs of Selection to get the ID number for one element.
Figure 23: ElementId
In the Revit Platform API, you can create an ElementId directly, and then associate a unique integer value to the new ElementId. The new ElementId value is 0 by default.
Code Region 5-3: Setting ElementId |
// Get the id of the element Autodesk.Revit.DB.ElementId selectedId = element.Id; int idInteger = selectedId.IntegerValue; // create a new id and set the value Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(idInteger); |
ElementId has the following uses:
Use ElementId to retrieve a specific element from Revit. From the Revit Application class, gain access to the active document, and then get the specified element using the Document.GetElement(ElementId) method.
Code Region 5-4: Using ElementId |
// Get the id of the element Autodesk.Revit.DB.ElementId selectedId = element.Id; int idInteger = selectedId.IntegerValue; // create a new id and set the value Autodesk.Revit.DB.ElementId id = new Autodesk.Revit.DB.ElementId(idInteger); // Get the element Autodesk.Revit.DB.Element first = document.GetElement(id); |
If the ID number does not exist in the project, the element you retrieve is null.
Every element has a UniqueId, represented by the String storage type. The UniqueId corresponds to the ElementId. However, unlike ElementId, UniqueId functions like a GUID (Globally Unique Identifier), which is unique across separate Revit projects. UniqueId can help you to track elements when you export Revit project files to other formats.
Code Region 5-5: UniqueId |
String uniqueId = element.UniqueId; |
The location of an object is important in the building modeling process. In Revit, some objects have a point location. For example a table has a point location. Other objects have a line location, representing a location curve or no location at all. A wall is an element that has a line location.
The Revit Platform API provides the Location class and location functionality for most elements. For example, it has the Move() and Rotate() methods to translate and rotate the elements. However, the Location class has no property from which you can get information such as a coordinate. In this situation, downcast the Location object to its subclass-like LocationPoint or LocationCurve-for more detailed location information and control using object derivatives.
Retrieving an element's physical location in a project is useful when you get the geometry of an object. The following rules apply when you retrieve a location:
In the Revit Platform API, curve-driven means that the geometry or location of an element is determined by one or more associated curves. Almost all analytical model elements are curve-driven - linear and area loads, walls, framing elements, and so on.
Other Elements cannot retrieve a LocationCurve or LocationPoint. They return Location with no information.
Table 12: Elements Location Information
Location Information |
Elements |
LocationCurve |
Wall, Beam, Brace, Structural Truss, LineLoad(without host) |
LocationPoint |
Room, RoomTag, SpotDimension, Group, Column, Mass |
Only Location |
Level, Floor, some Tags, BeamSystem, Rebar, Reinforcement, PointLoad, AreaLoad(without Host), Span Direction(IndependentTag) |
No Location |
View, LineLoad(with host), AreaLoad(with Host), BoundaryCondition |
Some FamilyInstance LocationPoints, such as all in-place-FamilyInstances and masses, are specified to point (0, 0, 0) when they are created. The LocationPoint coordinate is changed if you transform or move the instance.
To change a Group-s LocationPoint, do one of the following:
For more information about LocationCurve and LocationPoint, see Move.
Levels are finite horizontal planes that act as a reference for level-hosted or level-based elements, such as roofs, floors, and ceilings. The Revit Platform API provides a Level class to represent level lines in Revit. Get the Level object to which the element is assigned using the API if the element is level-based.
Code Region 5-6: Assigning Level |
// Get the level object to which the element is assigned. Level level = element.Level; |
A number of elements, such as a column, use a level as a basic reference. When you get the column level, the level you retrieve is the Base Level.
Figure 24: Column Base Level parameter
Level is the most commonly used element in Revit. In the Revit Platform API, all levels in the project are located by iterating over the entire project and searching for Elements.Level objects.
For more Level details, see Datum and Information Elements.
Every element has a set of parameters that users can view and edit in Revit. The parameters are visible in the Element Properties dialog box (select any element and click the Properties button next to the type selector). For example, the following image shows Room parameters.
Figure 25: Room parameters
In the Revit Platform API, each Element object has a Parameters property, which is a collection of all the properties attached to the Element. You can change the property values in the collection. For example, you can get the area of a room from the room object parameters; additionally, you can set the room number using the room object parameters. The Parameter is another way to provide access to property information not exposed in the element object.
In general, every element parameter has an associated parameter ID. Parameter IDs are represented by the ElementId class. For user-created parameters, the IDs correspond to real elements in the document. However, most parameters are built-in and their IDs are constants stored in ElementIds.
Parameter is a generic form of data storage in elements. In the Revit Platform API, it is best to use the built-in parameter ID to get the parameter. Revit has a large number of built-in parameters available using the BuiltInParameter enumerated type.
For more details, see Parameters.