Creating and Editing Schedules

Schedules can be created and adjusted via the Revit API. In this example, we'll keep things simple and create a schedule that lists all the walls in our file and their lengths.

To do this, we'll use ViewSchedule.CreateSchedule(), which takes three arguments:

  • The document we want to add our sheet to.
  • The Element ID of the category we want to analyse.
  • The Element ID of the area scheme we want to use. We won't be looking at areas in this post, so we'll pass an invalid element ID to skip it.
doc = DocumentManager.Instance.CurrentDBDocument
wall_category_id = ElementId(BuiltInCategory.OST_Walls)
TransactionManager.Instance.EnsureInTransaction(doc)
new_schedule = ViewSchedule.CreateSchedule(doc, wall_category_id, ElementId(-1)) #ElementId(-1) is an invalid ID. It is used to skip the area scheme.
TransactionManager.Instance.TransactionTaskDone()
That should have created a new schedule. If we open that schedule, however, we see that it's empty. This is because we need to populate its fields. To do this, we'll change the schedule's definition.
schedulable_fields = new_schedule.Definition.GetSchedulableFields() #Every field we can add to the schedule.
for field in schedulable_fields:
name = field.GetName(doc)
if name == "Type":
typ_field = field
if name == "Length":
length_field = field
TransactionManager.Instance.EnsureInTransaction(doc)
new_schedule.Definition.AddField(typ_field)
new_schedule.Definition.AddField(length_field)
TransactionManager.Instance.TransactionTaskDone()
The schedule should now contain your desired fields.

To overwrite the schedule's parameters (its name, for instance), follow the logic outlined in this post.

Comments

Popular posts from this blog

Check which user owns an element in a shared model

Create dimensions

Create Dimensions - Rooms