AddField Method (SchedulableField)


Schedule Definition Add Field(Schedulable Field) Method

Adds a regular field at the end of the list.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public ScheduleField AddField(
	SchedulableField schedulableField
)

Parameters

schedulableField SchedulableField
A SchedulableField object representing the field.

Return Value

ScheduleField
The new field.
Exceptions
Exception Condition
ArgumentException The field specified by schedulableField may not included in this ScheduleDefinition. -or- The field specified by schedulableField is already included in this ScheduleDefinition.
ArgumentNullException A non-optional argument was null
Example
/// <summary>
/// Add fields to view schedule.
/// </summary>
/// <param name="schedules">List of view schedule.</param>
public void AddFieldToSchedule(Document document, List<ViewSchedule> schedules)
{
    using (Transaction transaction = new Transaction(document, "Adding fields to schedule"))
    {
        transaction.Start();

        foreach (ViewSchedule vs in schedules)
        {
           //Get all schedulable fields from view schedule definition.
           IList<SchedulableField> schedulableFields = vs.Definition.GetSchedulableFields();

           foreach (SchedulableField sf in schedulableFields)
           {
               bool fieldAlreadyAdded = false;
               //Get all schedule field ids
               IList<ScheduleFieldId> ids = vs.Definition.GetFieldOrder();
               foreach (ScheduleFieldId id in ids)
               {
                   // If the GetSchedulableField() method of gotten schedule field returns same
                   // schedulable field, it means the field is already added to the view schedule.
                   if (vs.Definition.GetField(id).GetSchedulableField() == sf)
                   {
                       fieldAlreadyAdded = true;
                       break;
                   }
               }

               //If schedulable field doesn't exist in view schedule, add it.
               if (fieldAlreadyAdded == false)
               {
                   vs.Definition.AddField(sf);
               }
           }
        }

        transaction.Commit();
    }   
}
See Also
ArchiLabs Desktop

Put AI to work inside Revit.

Give Desktop your instructions and project files to build Revit families, update model elements, and create views and schedules. Works directly in Revit and AutoCAD.

Explore Desktop →