Skill v1.0.0
currentAutomated scan100/100version: "1.0.0" name: scheduling description: Schedules and quantities. Covers creating schedules, adding fields, filters, sorting and grouping, reading schedule contents, placing schedules on sheets, and preparing them for export. Use it for "make a door schedule", "count windows by type", "export the room schedule" and similar tasks.
Scheduling
Read revit-scripting first. Check API names with lookup_revit_api.
Answering a quantity question
A run_query over the elements is usually more reliable and faster than building a schedule and reading it back. Build a schedule when the user wants one in the model.
Creating a schedule
cat_id = DB.Category.GetCategory(doc, DB.BuiltInCategory.OST_Doors).Idschedule = DB.ViewSchedule.CreateSchedule(doc, cat_id)schedule.Name = "Door Schedule"definition = schedule.Definition
- Other kinds: key schedules
DB.ViewSchedule.CreateKeySchedule(doc, cat_id), material takeoffsCreateMaterialTakeoff(doc, cat_id), sheet listsCreateSheetList(doc).
Fields
fields = {}for sf in definition.GetSchedulableFields():fields[sf.GetName(doc)] = sfmark = definition.AddField(fields["Mark"])width = definition.AddField(fields["Width"])
- Available fields:
GetSchedulableFields()lists what can be scheduled for that category. Its display names are localized, so discover them in the active Revit session instead of hardcoding English labels. - Field ids:
AddFieldreturns aScheduleField. ItsFieldIdis what filters and sorting use. - Order: fields appear in the order they are added.
- Hiding a field: set
field.IsHidden = Trueto keep it for filtering or sorting but not show it.
Filters, sorting, grouping, totals
definition.AddFilter(DB.ScheduleFilter(level.FieldId, DB.ScheduleFilterType.Equal, "Level 1"))definition.AddSortGroupField(DB.ScheduleSortGroupField(mark.FieldId))definition.IsItemized = Falsedefinition.ShowGrandTotal = True
- Grouping identical rows:
definition.IsItemized = Falsemerges rows with the same values;Truelists every element.
- Filter values must match the field's storage type: a string, a double in feet, an int, or an ElementId.
- Headers and footers: grouping headers and footers are properties of
ScheduleSortGroupField(ShowHeader,ShowFooter).
Reading schedule contents
table = schedule.GetTableData()body = table.GetSectionData(DB.SectionType.Body)rows = []for r in range(body.NumberOfRows):rows.append([schedule.GetCellText(DB.SectionType.Body, r, c) for c in range(body.NumberOfColumns)])result = rows
The first body rows can be column headers, depending on the schedule's settings.
Placing on a sheet
DB.ScheduleSheetInstance.Create(doc, sheet.Id, schedule.Id, DB.XYZ(x, y, 0))
- Sheet coordinates are in feet, measured from the sheet origin.
Exporting
Guarded agent runs block schedule exports. Prepare and verify the schedule in a run, then have the user export it from Revit after the run ends.
Before you report done
- [ ] The schedule's rows, read back, match a direct element query of the same category and filters.
- [ ] Its fields, filters, sorting and totals, read back from
schedule.Definition, are the ones asked for. - [ ]
capture_view(view="Door Schedule")shows how it looks. - [ ] You told the user the schedule's name and that it is ready to export from Revit.