Schedules Filtering - Add More Schedules

Hi everyone,

I have a script to replace the filter values in the schedules. Does someone know how I could improve my python code in order to feed the first input (IN[0]) of the python node with more than only one “View”? thanks a lot!

Here is the code

import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *


# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager


# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *


doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application


from System.Collections.Generic import *


# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

refschedule = UnwrapElement(IN[0])
tgtschedules = UnwrapElement(IN[1])
tgtstrings = IN[2]

refdefinition = refschedule.Definition
reffilter = refdefinition.GetFilter(0)

tgtdefinitions = []
tgtfilters = []

TransactionManager.Instance.EnsureInTransaction(doc)

a = refdefinition.GetFieldId(0)
b = reffilter.FilterType

for tgtschedule in tgtschedules:
	tgtdefinition = tgtschedule.Definition
	tgtdefinitions.append(tgtdefinition)

for tgtstring in tgtstrings:
	tgtfilter = ScheduleFilter(a, b, tgtstring)
	tgtfilters.append(tgtfilter)

for tgtdefinition, tgtfilter in zip(tgtdefinitions, tgtfilters):
	tgtdefinition.SetFilter(0,tgtfilter)

TransactionManager.Instance.TransactionTaskDone()

OUT = len(tgtdefinitions);

Hi @ste_camp , thanks for starting the new thread.
Here’s one way you could do that:

change the line :

refschedule = UnwrapElement(IN[0])

with :

if isinstance(IN[0],list):
	refschedule = [UnwrapElement(i) for i in IN[0]]
else:
	refschedule  = [UnwrapElement(IN[0])]

then iterate through the list of refschedules: ( i took the transaction out of the loop so you don’t start a new transaction at each iteratio…)

TransactionManager.Instance.EnsureInTransaction(doc)

for r in refschedule:

	refdefinition = r.Definition
	reffilter = refdefinition.GetFilter(0)
	
	tgtdefinitions = []
	tgtfilters = []
	

	
	a = refdefinition.GetFieldId(0)
	b = reffilter.FilterType
	
	for tgtschedule in tgtschedules:
		tgtdefinition = tgtschedule.Definition
		tgtdefinitions.append(tgtdefinition)
	
	for tgtstring in tgtstrings:
		tgtfilter = ScheduleFilter(a, b, tgtstring)
		tgtfilters.append(tgtfilter)
	
	for tgtdefinition, tgtfilter in zip(tgtdefinitions, tgtfilters):
		tgtdefinition.SetFilter(0,tgtfilter)
	

TransactionManager.Instance.TransactionTaskDone()

OUT = len(tgtdefinitions)
2 Likes

Hi Mostafa_El_Ayoubi,

it works perfectly! thank you so much!

1 Like

hey there,

I’ve been using this node is some of my scripts but i noticed something odd…
So far the node always worked, but now i notice it doesn’t work on Assembly Schedules, i can’t change the filter.
It’s either this, or the filter doens’t work because it doesn’t recognise shared parameters.
Does anyone else have this too? And if so, how could this possibly be fixed?

cheers~