Get Filters rule in Python

Hi everyone,

I’m trying to manage filters from Excel. I’ve been able to create (import) filters from a csv files, I would like now to get filters rule information back to Excel.

I’ve seen this topic but I’ve been unable to get the ParameterFilterElement name and the filter type parameter ("contains’, “Equals”, …).

Is it possible via a Python script to get these fulter rules information, or is it not available ?
I would like a Python script to implement it later on with PyRevit.

Revit version supported from 2022.

Thanks for your help.

You can get the Filter Rule String with a clockwork node - like this


If you require a breakdown of the rule I would crack open the clockwork node and change it to return a list rather than a string

Thanks a lot @Mike.Buttery
It is what I was looking for.
I will look into this python code and reformat for my need.

FilterRuleString from Clockwork node get everything from highlighted in green.
This topic provide a python script to get categories for each parameterFilterElement.

Is there a way to get also what is highlighted in Red (the categories for each rules)?

Hi @clementcazi you can try something here if it what you mean …


Home.dyn (6.7 KB)

The ParameterFilterElement.GetCategories() method returns a list of category ids, from there you can get the names like this

# For single ParameterFilterElement
pfe = UnwrapElement(IN[0])
cats =pfe.GetCategories()
cat_names = [Category.GetCategory(doc, cat_id).Name for cat_id in cats]
1 Like

Hi @sovitek,

your script ouput the categories applied to this filter, meaning if the rule is set to “All selected categories”.
I’m looking if the rule is set to a specific category.

The individual categories of a filter are available from each element filter and only if the logical filter is an ‘or’ filter. It gets a little inception-y with lots of layers, thankfully when you get to the third layer it doesn’t take 8000 times longer

ParameterFilterElement.GetElementFilter()
│
├─ LogicalOrFilter.GetFilters()
|  |
|  ├─ ElementParameterFilter().GetRules() <- If this uses all categories there will
|  |  |                                      not be any FilterCategoryRule elements
|  |  └─ FilterCategoryRule.GetCategories()
|  |     | 
|  |     └─ Doors                         <- Individual category
|  |
|  ├─ ElementParameterFilter().GetRules()
|  |  |
|  |  └─ FilterCategoryRule.GetCategories()
|  |     | 
|  |     └─ Walls
etc...