How to get nested split schedules

Hello everyone,

I need help getting the nested view schedules that were split from a schedule. I’ll go over the context, problem, code and finally methods I have tried.

Context:
I have a number of sheets and each one has a single schedule by the name of “CUT LIST”. These schedules are usually too long so I typically just manually split it in half using “Split Schedule Table.” This lays each half of the schedule side by side on the sheet and displays like this in the Project Browser:

S1 - CUT LIST
├── S1 - CUT LIST 1/2
└── S1 - CUT LIST 2/2

I thought it would be useful to write a script that essentially takes a selection of sheets and programmatically splits the schedule in half.

Problem:
After using the Split method I expected it to automatically place or rather replace the original whole schedule with its halves. The method successfully split the schedule in two halves but that’s about it. I then thought I could achieve the rest as such:

  1. Delete the whole schedule instance from the sheet
  2. Get the two split halves
  3. Place the halves onto the sheet.

The problem lies in getting the two nested halves. The print statement simply outputs “1”, which tells me that split_schedules is simply retrieving the top level schedule and not the nested halves.

Code:

schedules = [get_cut_list(s) for s in sheets]
if schedules:
    all_schedules = FilteredElementCollector(doc).OfClass(ViewSchedule).ToElements()

    for schedule_instance in schedules:
        schedule_name = schedule_instance.Name
        schedule_view = doc.GetElement(schedule_instance.ScheduleId)

        with revit.Transaction('Split Cut List', doc):
            schedule_view.Split(2)

        with revit.Transaction('Delete Cut List Instance', doc):
            doc.Delete(schedule_instance.Id)

        split_schedules = [sch for sch in all_schedules if schedule_name in sch.Name]
        print(len(split_schedules))
        
       # Place split schedules on sheet...

Methods I have tried:

  • GetDependentViewIds
  • GetDependentElements
  • GetSubElements

Is there a method to retrieve nested split schedules that I am missing or perhaps another workaround?

The problem here is that all_schedules list doesn’t change when you split and delete schedules in the loop.
You have to use the filteredelementcolector again (and maybe look at the various available filters to search for the name directly)

Thank you for the response. On second glance I have no idea how I missed that haha. However, after this adjustment:

# Schedule view is split above as before

all_schedules = FilteredElementCollector(doc).OfClass(ViewSchedule).ToElements()
split_schedules = [sch for sch in all_schedules if schedule_name in sch.Name]
print(len(split_schedules))
        
# Place split schedules on sheet...

I am somehow still unable to get any nested schedules and instead the print statement still outputs “1” for the main whole schedule. Should I assume this to be a limitation in the API?

Before going any further, I would you Revit lookup to explore the relationship between schedules, split schedules parts and placed ones.

2 Likes

I’ll be sure to do that, thank you!

I have found a solution:

My mistake was that I was trying to get the split schedule elements themselves to then place on a sheet. I later realized that the Create method used for creating an instance of a schedule on a sheet has an additional fifth argument segmentIndex As Integer, which is exactly what I needed in order to place the segments of the original schedule on a sheet.

for s in sheets:
    schedule_instance = get_cut_list(s)
    schedule_view = doc.GetElement(schedule_instance.ScheduleId)
    default_point = schedule_instance.Point
    shifted_point = XYZ(default_point.X + .2, default_point.Y, default_point.Z)

    with revit.Transaction('Delete Cut List Instance', doc):
        doc.Delete(schedule_instance.Id)

    with revit.Transaction('Split Cut List', doc):
        schedule_view.Split(2)

    with revit.Transaction('Place Cut List Segments', doc):
        ScheduleSheetInstance.Create(doc, s.Id, schedule_view.Id, default_point, 0)
        ScheduleSheetInstance.Create(doc, s.Id, schedule_view.Id, shifted_point, 1)
3 Likes