Welcome to the third tutorial of Revit API series, this post is to cover how to create a Revit Schedule including filter and sorting/grouping. For this, we gonna need to write an ExternalCommand Revit Add-Ins to create a Wall Schedule.
You can follow the first part of this tutorial to setup the project. After setting up your project, as shown in figure 1.0, we have to make a BuiltInParameter list for BuiltInParameters; Family and Type, Base Constraint, Area and Length, to add in our Wall schedule as schedule’s fields. (see here how to get BuiltInParameter object)
In the Execute method, create two variable for UIDocument and Document and start Transaction. ViewSchedule has CreateSchedule method to create a schedule with Document and CategoryId as parameters. As shown in figure 1.1, we provided WallCategoryId to create a Wall Schedule and name it “Wall Schedule Sample”. Define two variables to hold Schedule’s sorting/grouping field and Schedule’s filter field. (figure 1.1)
From ScheduleDefinition’s GetSchedulableFields method, we can get a list of fields that are eligible to be included in our Wall schedule (figure 1.2). And iterate each ScheduleField to check whether it is in our selected parameter list (BiParams) or not. We will write a Boolean method called “CheckField” for this logic (as shown in figure 1.3). If the result is true, we will add it in our Wall schedule by using AddField() method.
CheckField method is a custom helper method to check whether ScheduleField’s parmeterId is equal BuiltInParameter’s Id or not (figure 1.3).
In figure 1.1, we have defined two variables to hold Schedule’s sorting/grouping field and Schedule’s filter field. After adding Field to our Wall Schedule, we’ll collect Base Constraint’s ScheduleField , by comparing whether ScheduleField represents Base Constraint parameter or not, to create a filter for our Wall schedule. We chose ScheduleFilter Constructor that requires three arguments : ScheduleField’s FieldId, ScheuleFilterType which is a filter rule (Equal, Contains, Begins With …) and an ElementId for filter value. As you can see in figure 1.4, we have provided Base Constraint’s FieldId, FilterType/Rule is Equal, and FilterValue is Level 1’s Id. “GetLevelByName” is another custom method to collect Level element by Name. (figure 1.5)
For schedule’s group sorting, we’ll collect “Family and Type” ScheudleField to create schedule’s sorting field for our Wall schedule. And also we chose ScheduleSortGroupField Constructor that requires only ScheduleField’s FieldId, provided accordingly as shown in figure 1.4.
Lastly, after we have added Filter field and Sorting field to our WallSchedule’s, just have to set both values through ScheduleDefinition’s SetFilter method and SetSortGroupField accordingly with indexes of the fields. (figure 1.6)
That’s all for this post, you can find complete source code from here, Cheers!