Hello!
Here is the problem I am trying to solve. A user created Rule-based Filters named ID LO-XX2 and the filter rule is ID does not contain LO-XX2. There’s a lot of these. The LO was supposed to be L0 (Level Zero not Level Letter O). I was able to write a dynamo script to rename the Filter by replacing the LO to L0, but cannot figure out how to modify the Filter Rule String itself. I don’t want to Create new filters, because there are about 50 views with these already applied to.
I wanted to do a two part process basically. If Filter Rule String contains LO- replace it with L0-. Then run the Dynamo Script that renames the Filter rules.
Thoughts?
since u’ve already grabbed filter elements and renamed them, worth trying is to SetRules while u’re at it. SetRules Method
Thank you. I guess I am not sure how to do that. I am really new to Dynamo and have been using nodes that already exist. So not sure how to use the API documents yet.
aite lets tinker around a bit, see if it’s doable. also there might be a node-only approach that i don’t even konw.
@michellel I stared at this filter and that filter for a full hour, not fun
, not to mention the document link I posted was from 2019 and already outdated. anyway, i found a workable solution (code-only) which might be a lot to take in. however, if u ever want to give it a try, u could refer to this. tbh, there might be a simpler approach, worthing diggin deeper into the doc.
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
# grab the ParameterFilterElements with "LO" in their names
v_filters = FilteredElementCollector(doc).OfClass(ParameterFilterElement).ToElements()
v_filters = list(filter(lambda f: "LO" in f.Name, v_filters))
#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for f in v_filters: # ParameterFilterElement
e_filter = f.GetElementFilter() # ElementFilter -> ElementLogicalFilter -> LogicalAndFilter
e_param_filter = e_filter.GetFilters()[0] # ElementParameterFilter
rule = e_param_filter.GetRules()[0] # FilterRules, returns a set of copies
rule.RuleString = "Placeholder" # still, a copy
# make a new ElementParameterFilter with the modified copy
new_e_param_filter = ElementParameterFilter(List[FilterRule]([rule]))
f.SetElementFilter(new_e_param_filter) # update the ParameterFilterElement
f.Name = f.Name.replace("LO", "L0") # update the filter name
TransactionManager.Instance.TransactionTaskDone()
essentially, u could start with a filter then get logical filter → parameter filter → rules (copy) → make new rules → make new parameter filter → set new filter onto the filter → rename the filter (which u’ve already done with nodes)
before running:
after:
my goodness, ‘filter’ is going to haunt my nightmares for a while.
Just to clarify, are there multiple filters that need to be modified or multiple views containing a single filter?

