A schedule is a tabular representation of data. A typical schedule shows all elements of a category (doors, rooms, etc.) with each row representing an element and each column representing a parameter.
The ViewSchedule class represents schedules and other schedule-like views, including single-category and multi-category schedules, key schedules, material takeoffs, view lists, sheet lists, keynote legends, revision schedules, and note blocks.
The ViewSchedule.Export() method will export the schedule data to a text file.
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.
public ViewSchedule ViewSchedule.CreateSchedule(Document document, ElementId categoryId); |
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.
FilteredElementCollector collector1 = new FilteredElementCollector(doc); collector1.OfCategory(BuiltInCategory.OST_AreaSchemes); //Get first ElementId of AreaScheme. ElementId areaSchemeId = collector1.FirstElementId(); //If you want to create an area schedule, you must use CreateSchedule method with three arguments. //The input of second argument must be ElementId of BuiltInCategory.OST_Areas category and the input of third argument must be ElementId of a areaScheme. ViewSchedule areaSchedule = Autodesk.Revit.DB.ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Areas), areaSchemeId); |
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.
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.
//Get first ElementId of AnnotationSymbolType families.
ElementId annotationSymbolTypeId = ElementId.InvalidElementId;
if (!doc.AnnotationSymbolTypes.IsEmpty)
{
foreach (AnnotationSymbolType type in doc.AnnotationSymbolTypes)
{
annotationSymbolTypeId = type.Family.Id;
break;
}
}
//Create a noteblock view schedule.
ViewSchedule noteBlockSchedule = ViewSchedule.CreateNoteBlock(doc, annotationSymbolTypeId);
|
The ScheduleDefinition class contains various settings that define the contents of a schedule view, including:
Most schedules contain a single ScheduleDefinition which is retrieved via the ViewSchedule.Definition property. In Revit MEP, schedules of certain categories can contain an "embedded schedule" containing elements associated with the elements in the primary schedule, for example a room schedule showing the elements inside each room or a duct system schedule showing the elements associated with each system. An embedded schedule has its own category, fields, filters, etc. Those settings are stored in a second ScheduleDefinition object. When present, the embedded ScheduleDefinition is obtained from the ScheduleDefinition.EmbeddedDefinition property.
Once a ViewSchedule is created, fields can be added. The ScheduleDefinition.GetSchedulableFields() method will return a list of SchedulableField objects representing the non-calculated fields that may be included in the schedule. A new field can be added from a SchedulableField object or using a ScheduleFieldType. The following table describes the options available from the ScheduleFieldType enumeration.
| Member name | Description |
|---|---|
| Instance | An instance parameter of the scheduled elements. All shared parameters also use this type, regardless of whether they are instance or type parameters. |
| ElementType | A type parameter of the scheduled elements. |
| Count | The number of elements appearing on the schedule row. |
| ViewBased | A specialized type of field used for a few parameters whose displayed values can change based on the settings of the view:
|
| Formula | A formula calculated from the values of other fields in the schedule. |
| Percentage | A value indicating what percent of the total of another field each element represents. |
| Room | A parameter of the room that a scheduled element belongs to. |
| FromRoom | A parameter of the room on the "from" side of a door or window. |
| ToRoom | A parameter of the room on the "to" side of a door or window. |
| ProjectInfo | A parameter of the Project Info element in the project that the scheduled element belongs to, which may be a linked file. Only allowed in schedules that include elements from linked files. |
| Material | In a material takeoff, a parameter of one of the materials of a scheduled element. |
| MaterialQuantity | In a material takeoff, a value representing how a particular material is used within a scheduled element. The parameter ID can be MATERIAL_AREA, MATERIAL_VOLUME, or MATERIAL_ASPAINT. |
| RevitLinkInstance | A parameter of the RevitLinkInstance that an element in a linked file belongs to. Currently RVT_LINK_INSTANCE_NAME is the only supported parameter. Only allowed in schedules that include elements from linked files. |
| RevitLinkType | A parameter of the RevitLinkType that an element in a linked file belongs to. Currently RVT_LINK_FILE_NAME_WITHOUT_EXT is the only supported parameter. Only allowed in schedules that include elements from linked files. |
| StructuralMaterial | A parameter of the structural material of a scheduled element. |
| Space | A parameter of the space that a scheduled element belongs to. |
Using one of the ScheduleDefinition.AddField() methods will add the field to the end of the field list. To place a new field in a specific location in the field list, use one of the ScheduleDefinition.InsertField() methods. Fields can also be ordered after the fact using ScheduleDefinition.SetFieldOrder().
The following is a simple example showing how to add fields to a view if they are not already in the view schedule.
/// <summary>
/// Add fields to view schedule.
/// </summary>
/// <param name="schedules">List of view schedule.</param>
public void AddFieldToSchedule(List<ViewSchedule> schedules)
{
IList<SchedulableField> schedulableFields = null;
foreach (ViewSchedule vs in schedules)
{
//Get all schedulable fields from view schedule definition.
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);
}
}
}
}
|
The ScheduleField class represents a single field in a ScheduleDefinition's list of fields. Each (non-hidden) field becomes a column in the schedule.
Most commonly, a field represents an instance or type parameter of elements appearing in the schedule. Some fields represent parameters of other related elements, like the room to which a scheduled element belongs. Fields can also represent data calculated from other fields in the schedule, specifically Formula and Percentage fields.
The ScheduleField class has properties to control column headings, both the text as well as the orientation. Column width and horizontal alignment of text within a column can also be defined.
The ScheduleField.IsHidden property can be used to hide a field. A hidden field is not displayed in the schedule, but it can be used for filtering, sorting, grouping, and conditional formatting and can be referenced by Formula and Percentage fields.
Some ScheduleFields can be totaled and if the HasTotals property is set to true, totals will be displayed if a footer row is enabled where the totals will be displayed. It can either be a grand total row at the end of the schedule or a footer row for one of the schedule's grouped fields. In a non-itemized schedule, totals are also displayed in regular rows when multiple elements appear on the same row.
A schedule may be sorted or grouped by one or more of the schedule's fields. Several methods can be used to control grouping and sorting of fields. The ScheduleSortGroupField class represents one of the fields that the schedule is sorted or grouped by. Sorting and grouping are related operations. In either case, elements appearing in the schedule are sorted based on their values for the field by which the schedule is sorted/grouped, which automatically causes elements with identical values to be grouped together. By enabling extra header, footer, or blank rows, visual separation between groups can be achieved.
If the ScheduleDefinition.IsItemized property is false, elements having the same values for all of the fields used for sorting/grouping will be combined onto the same row. Otherwise the schedule displays each element on a separate row
A schedule can be sorted or grouped by data that is not displayed in the schedule by marking the field used for sorting/grouping as hidden using the ScheduleField.IsHidden property.
A ScheduleFilter can be used to filter the elements that will be displayed in a schedule. A filter is a condition that must be satisfied for an element to appear in the schedule. All filters must be satisfied for an element to appear in the schedule.
A schedule can be filtered by data that is not displayed in the schedule by marking the field used for filtering as hidden using the ScheduleField.IsHidden property.
The static ScheduleSheetInstance.Create() method creates an instance of a schedule on a sheet. It requires the ID of the sheet where the schedule will be placed, the ID of the schedule view, and the XYZ location on the sheet where the schedule will be placed. The ScheduleSheetInstance object has properties to access the ID of the "master" schedule that generates this ScheduleSheetInstance, the rotation of the schedule on the sheet, the location on the sheet where the schedule is placed (in sheet coordinates), as well as a flag that identifies if the ScheduleSheetInstance is a revision schedule in a titleblock family.