Revit API : Schedule Creation

Welcome to the third tutorial of Revit API series, this post is to cover how to creates 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.

Schedule Creation Demo

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)

figure 1.0

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)

figure 1.1 – Execute Method

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.

figure 1.2 – GetSchedulableFields

CheckField method is a custom helper method to check whether ScheduleField’s parmeterId is equal BuiltInParameter’s Id or not (figure 1.3).

figure 1.3 – CheckField Method

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.

figure 1.4 – ScheduleFilter & ScheduleSortGroupField
figure 1.5 – GetLevelByName

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)

figure 1.6 – Set Values

That’s all for this post, you can find complete source code from here, Cheers!

Advertisement

5 thoughts on “Revit API : Schedule Creation

  1. Me gustaria adicionar un parametro Compartido.Alguna idea?

    I would like to add a Shared parameter. Any ideas?

    Like

  2. Another question, how can I order it?
    I have
    private static BuiltInParameter[] BiParams = new BuiltInParameter[]
    { BuiltInParameter.RBS_SECTION,
    BuiltInParameter.RBS_PIPE_FIXTURE_UNITS_PARAM,
    BuiltInParameter.RBS_PIPE_DIAMETER_PARAM,
    BuiltInParameter.CURVE_ELEM_LENGTH,
    BuiltInParameter.RBS_PIPE_PRESSUREDROP_PARAM
    };
    and I get
    Fixture Units || Diameter || Pressure Drop | |Section||Length
    I don’t know how to send you the table, but this is the table header, the order does not match

    Like

    1. Try with List*T* , something like this;

      List *BuiltInParameter* BiParams = new List*BuiltInParameter* () {BuiltInParameter.RBS_SECTION,
      BuiltInParameter.RBS_PIPE_FIXTURE_UNITS_PARAM, … };

      Note: “Angle Brackets” do not support in comment, instead i typed “*” .

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.