So I ran into what appears to be the same issue that it appears this person ran into here:
In my script, which I’ll put below, I used python to look for a certain string in a filter value, replace it, and re-apply the filter.
It works, the filter gets changed, but the schedule won’t update unless I manually click the filter button and then close the window. This works whether or not I make any changes to the filters.
It’s odd, I have a number of scripts regarding schedule filters - One that adds filters, one that removes filters, one that replaces a filter value entirely…
All of them work just fine, it wasn’t until this script that I ran into an error.
I tried using RefreshData(), but that didn’t do anything. I’ve tried regenerating the document, which didn’t do anything either. I’ve tried using some of the other scripts mentioned to add, and then remove a filter, but to no avail.
I’m pretty stumped here. Anyone have any ideas? I’d really prefer not to click the filter button and then close the window for all 200 schedules
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
# Import Revit elements & geometry conversion methods
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
#The System namespace at the root of .NET
import System
# Import RevitAPI - This gives general access to Revit tools.
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager & TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
#Active Revit file
doc = DocumentManager.Instance.CurrentDBDocument
#UI level interfaces
uiapp = DocumentManager.Instance.CurrentUIApplication
#Current instance of Revit
app = uiapp.Application
#UI level interfaces of the current instance of Revit
uidoc = uiapp.ActiveUIDocument
# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
column_header = IN[1]
find = IN[2]
replace = IN[3]
#Start Code
sel = uidoc.Selection.GetElementIds()
sel = [doc.GetElement(x) for x in sel]
TransactionManager.Instance.EnsureInTransaction(doc)
for sched in sel:
sched = sched.Definition
count = range(sched.GetFilterCount())
filters = [sched.GetFilter(x) for x in count]
field_ids = [sched.GetFilter(x).FieldId for x in count]
field = [sched.GetField(x) for x in field_ids]
field_names = [x.GetName() for x in field]
filt_idx = field_names.index(column_header)
filt = sched.GetFilter(filt_idx)
filt_val = filt.GetStringValue()
new = filt_val.replace(find, replace)
filt.SetValue(replace)
sched.SetFilter(filt_idx, filt)
TransactionManager.Instance.TransactionTaskDone()
#Assign output
OUT = 0