The Autodesk.Revit.DB.ElementRecord
class is a data class in Revit which represents the data recorded for an element. It provides a way to access and modify the record of an element in the database.
The ElementRecord
class has the following properties:
ElementId
: Gets the id of the element associated with the record.FieldCount
: Gets the number of fields in the record.Fields
: Gets or sets the fields of the record as a list of ElementRecordField
objects.The ElementRecord
class has the following methods:
GetField(int index)
: Gets the ElementRecordField
at the given zero-based index from the fields list.SetField(int index, ElementRecordField field)
: Sets the ElementRecordField
at the given zero-based index to the specified field.AddField(ElementRecordField field)
: Adds the specified ElementRecordField
to the end of the fields list.RemoveField(int index)
: Removes the ElementRecordField
at the given zero-based index from the fields list.ElementRecord
class enables users to manipulate custom fields added to elements in Revit.ElementRecord
instance must be saved to the database using a transaction.The following code snippet demonstrates how to create an ElementRecord
instance and add a custom field to it.
ElementId elementId = new ElementId(123);
Element element = doc.GetElement(elementId);
ElementRecord record = new ElementRecord(elementId);
ElementRecordField field = new ElementRecordField("MyField", "MyValue");
record.AddField(field);
using (Transaction tx = new Transaction(doc, "Add element field"))
{
tx.Start();
doc.Regenerate();
element.SetElementRecord(record);
tx.Commit();
}
This code creates an element record for the element with id 123, adds a custom field "MyField" with value "MyValue" to it, and sets the record for the element.