Creating a Schedule

Creating a Schedule

The ViewSchedule class has several methods for creating new schedules depending on the type of schedule. All of the methods have a Document parameter that is the document to which the new schedule or schedule-like view will be added. The newly created schedule views will appear under the Schedules/Quantities node in the Project Browser.

A standard single-category or multi-category schedule can be created with the static ViewSchedule.CreateSchedule() method.

Code Region: Create a single-category schedule with 2 fields

public static void CreateSingleCategorySchedule(Document doc)
{
    using (Transaction t = new Transaction(doc, "Create single-category"))
    {
        t.Start();

        // Create schedule
        ViewSchedule vs = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Windows));

        doc.Regenerate();

        // Add fields to the schedule
        AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.WINDOW_HEIGHT));
        AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.WINDOW_WIDTH));

        t.Commit();
    }
}

/// <summary>
/// Adds a single parameter field to the schedule
/// </summary>
public static void AddRegularFieldToSchedule(ViewSchedule schedule, ElementId paramId)
{
    ScheduleDefinition definition = schedule.Definition;

    // Find a matching SchedulableField
    SchedulableField schedulableField =
        definition.GetSchedulableFields().FirstOrDefault<SchedulableField>(sf => sf.ParameterId == paramId);

    if (schedulableField != null)
    {
        // Add the found field
        definition.AddField(schedulableField);
    }
}

The second parameters the ID of the category whose elements will be included in the schedule, or InvalidElementId for a multi-category schedule.

A second CreateSchedule() method can be used to create an area schedule and takes an additional parameter that is the ID of an area scheme for the schedule.

Code Region: Creating an area schedule

FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfCategory(BuiltInCategory.OST_AreaSchemes);
//Get first ElementId of AreaScheme.
ElementId areaSchemeId = collector.FirstElementId();
if (areaSchemeId != null && areaSchemeId != ElementId.InvalidElementId)
{
    // If you want to create an area schedule, you must use CreateSchedule method with three arguments. 
    // The value of the second argument must be ElementId of BuiltInCategory.OST_Areas category
    // and the value of third argument must be ElementId of an AreaScheme.
    areaSchedule = Autodesk.Revit.DB.ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Areas), areaSchemeId);
}
A key schedule displays abstract "key" elements that can be used to populate parameters of ordinary model elements and can be created with the static ViewSchedule.CreateKeySchedule() method whose second parameter is the ID of the category of elements with which the schedule's keys will be associated.

A material takeoff is a schedule that displays information about the materials that make up elements in the model. Unlike regular schedules where each row (before grouping) represents a single element, each row in a material takeoff represents a single <element, material> pair. The ViewSchedule.CreateMaterialTakeoff() method has the same parameters as the ViewSchedule.CreateSchedule() method and allows for both single- and multi-category material takeoff schedules.

View lists, sheet lists, and keynote legends are associated with a designated category and therefore their creation methods do take a category ID as a parameter. A view list is a schedule of views in the project. It is a schedule of the Views category and is created using ViewSchedule.CreateViewList().

A sheet list is a schedule of sheets in the project. It is a schedule of the Sheets category and is created using the ViewSchedule.CreateSheetList() method.

A keynote legend is a schedule of the Keynote Tags category and is created using ViewSchedule.CreateKeynoteLegend().

Revision schedules are added to titleblock families and become visible as part of titleblocks on sheets. The ViewSchedule.CreateRevisionSchedule() method will throw an exception if the document passed in is not a titleblock family.

A note block is a schedule of the Generic Annotations category that shows elements of a single family rather than all elements in a category.

Code Region: ViewSchedule.CreateNoteBlock()

public ViewSchedule ViewSchedule.CreateNoteBlock(Document document, ElementId familyId);

The second parameter is the ID of the family whose elements will be included in the schedule.

Code Region: Creating a note block schedule

using (Transaction transaction = new Transaction(doc, "Creating Note BLock"))
{
    //Get first ElementId of a Note Block family.
    ICollection<ElementId> noteblockFamilies = ViewSchedule.GetValidFamiliesForNoteBlock(doc);
    ElementId symbolId = noteblockFamilies.First<ElementId>();
               
    if (!symbolId.Equals(ElementId.InvalidElementId))
    {
        transaction.Start();

        //Create a note-block view schedule.
        noteBlockSchedule = ViewSchedule.CreateNoteBlock(doc, symbolId);
    }

    if (null != areaSchedule)
    {
        transaction.Commit();
    }
    else
    {
        transaction.RollBack();
    }
}