Schedule add Filter Issue

Hi everybody,

I have a problem with adding a Filter to schedules that I create in the same script.

What I want to achieve is to create schedules for all the Rebar in the model, where I create a seperate schedule for each uniqie value for Schedule Mark. I then want to add a filter to each schedule to only show the Rebar that has the corresponding Schedule Mark value.

The problem is that when I run the script for the first time, the schedules are created but the Filter is not added. The ScheduleView.AddFilters node gives the following error:

*Warning: ScheduleView.AddFilters operation failed. *
The field ID is not the ID of a field in this ScheduleDefinition.
Parameter name: filter

If I then run the exact same script again, the error is resolved and the Filters are added correctly.
Any idea on how to make the script work correctly without having to run it twice? Below a graph of the script. The two inputs that aren’t shown are a List that contains the unique values for the Schedule Marks (in this case 1, 2 and 3).