Schedules Filtering - Replace Filter

hi everyone,

I’m trying to do this work, but I got stuck: I would like to replace a filer value of a schedule with a new value. I found a solution that allow me to create a new filter, but I can’t find the solution to replace the filter with the new one. I tried a lot of time but I didn’t find anything. Can someone help to to solve this problem?

Thanks!

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.InsertFilter(tgtfilter,0)

TransactionManager.Instance.TransactionTaskDone()

OUT = len(tgtdefinitions);

I have not tested it, but I think the ViewSchedule.Definition.SetFilter(index, ScheduleFilter) might be what you need, as the description states it’s function is “Replaces a Filter”.

Try it out and post back.

http://www.revitapidocs.com/2015/4432b9a9-a1ed-17c1-90a4-9c87d1a4fdcc.htm

1 Like

Hi Gui_Talarico,
thanks for your reply

i used the method that you show me and now it works! Thanks!
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);

can I ask you another help? now I can feed the python node just with one “View”. can you help me to edit the code in order to feed the python node with more than one “View”? thanks a lot!

1 Like

Try this

I think it need to distribute into each list

mmm no… it doesn’t work… I think that is a problem of the python code, not of dynamo

Hi @ste_camp , can you please start a new thread for that question? the original issue of this thread has been solved. Thanks!