# Get Filters rule in Python

**URL:** <https://forum.dynamobim.com/t/get-filters-rule-in-python/109331>\
**Category:** Revit\
**Tags:** python\
**Created:** [April 6, 2025, 10:52pm UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331 "2025-04-06T22:52:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![clementcazi](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@clementcazi](https://forum.dynamobim.com/u/clementcazi)\
**Post date:** [April 6, 2025, 10:52pm UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/1 "2025-04-06T22:52:28Z")

</div>

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](https://forum.dynamobim.com/t/get-filter-rule-information/91325/2) 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](https://discourse.pyrevitlabs.io/).

Revit version supported from 2022.

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [April 7, 2025, 12:03am UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/2 "2025-04-07T00:03:06Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/5/c504fc1a027e6586e81b1d4a38f751527717197f.png)  
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

---

<div class="post-metadata">

**Author:** ![clementcazi](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@clementcazi](https://forum.dynamobim.com/u/clementcazi)\
**Post date:** [April 7, 2025, 12:54am UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/3 "2025-04-07T00:54:22Z")

</div>

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](https://forum.dynamobim.com/t/getting-categories-of-view-filter-elements-in-dynamo/103526/9) 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)?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/4/b4d3ccca8a1b6b65d5fd88f579b0471da122af86.png)

---

<div class="post-metadata">

**Author:** ![sovitek](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/sovitek/32/116237_2.png) [@sovitek](https://forum.dynamobim.com/u/sovitek)\
**Post date:** [April 7, 2025, 5:45am UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/4 "2025-04-07T05:45:36Z")

</div>

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

 ![Skærmbillede 2025-04-07 074341](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/7/c7bf4feb6083ecf1d5848fae2c55d6b1be443692.png)  
[Home.dyn](https://forum.dynamobim.com/uploads/short-url/opBZmzAXoYUrvHO3SxeUn7RVRZo.dyn) (6.7 KB)

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [April 7, 2025, 6:11am UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/5 "2025-04-07T06:11:20Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![clementcazi](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@clementcazi](https://forum.dynamobim.com/u/clementcazi)\
**Post date:** [April 7, 2025, 10:29am UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/6 "2025-04-07T10:29:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [April 8, 2025, 1:35am UTC](https://forum.dynamobim.com/t/get-filters-rule-in-python/109331/7 "2025-04-08T01:35:59Z")

</div>

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

```plaintext
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...
```
