# Created Filter to View

**URL:** <https://forum.dynamobim.com/t/created-filter-to-view/21377>\
**Category:** Uncategorized\
**Created:** [April 25, 2018, 11:01am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377 "2018-04-25T11:01:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 25, 2018, 11:01am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/1 "2018-04-25T11:01:40Z")

</div>

Hello,

I have a peace of code to make a view filter, also a big thanks for Jonathan Olesen for bringing me so far. But is seems everything is working but the Filter doesn’t show up in the VG menu?

Anybody know what is going wrong…

Thanks

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/f/efeb4c4ceb6fd607c2da526c7f8fa8b79fa0780b.JPG)

```
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
def GetBuiltInParam(paramName):
	builtInParams = System.Enum.GetValues(BuiltInParameter)
	test = []
	for i in builtInParams:
		if i == paramName:
			test.append(i)
		else:
			pass
	return test
cats = IN[0]
paramName = IN[1]
pValue = IN[2]
view = UnwrapElement(IN[3])
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
castlst = []
for i in cats:
	castlst.append(ElementId(i.Id))
typedCatlist = castlst
rules = []
bip = GetBuiltInParam(paramName)
for el in bip:
	rules.append(ParameterFilterRuleFactory.CreateLessRule(ElementId(el), pValue, 0.001))
try:
	filter = ParameterFilterElement.Create(doc, 'Test', typedCatList, rules)
	view.AddFilter(filter.Id)
except:
	pass
TransactionManager.Instance.TransactionTaskDone()
OUT = view
```

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [April 25, 2018, 12:37pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/2 "2018-04-25T12:37:27Z")

</div>

I don’t think you can filter by Base Offset. Try creating your filter manually. If you can’t do it with Revit, Dynamo won’t be able to do it either.

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 25, 2018, 2:35pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/3 "2018-04-25T14:35:48Z")

</div>

Ow base offset was a test. Tested a lot parameters but no result. It must work of you take a look at the Archi lab nodes 😉

---

<div class="post-metadata">

**Author:** ![PauLtus](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paultus/32/48502_2.png) [@PauLtus](https://forum.dynamobim.com/u/PauLtus)\
**Post date:** [April 26, 2018, 6:14am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/4 "2018-04-26T06:14:00Z")

</div>

> [@Nick\_Boyts](#):
>
> If you can’t do it with Revit, Dynamo won’t be able to do it either.

That’s very much a truth.  
It’s just that Dynamo can process data a whole lot faster than our own weak mortal forms.

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 26, 2018, 7:07am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/5 "2018-04-26T07:07:43Z")

</div>

My wish is to create a structural plan with the view range applied and some filters created with dynamo.

Structural plan creation and View range is already working with dynamo/ python also the top level, bottom level range en Lookup/ down.

But the last thing, Filters as you can see in my topic is not working ☹ so you can’t apply a view template.  
if it’s not possible i will use Archi Lab but i Always like to know how things are working to better understand what i’m doning

---

<div class="post-metadata">

**Author:** ![Ernesto\_Pellegrino](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ernesto_pellegrino/32/105226_2.png) [@Ernesto\_Pellegrino](https://forum.dynamobim.com/u/Ernesto_Pellegrino)\
**Post date:** [April 26, 2018, 7:32am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/6 "2018-04-26T07:32:21Z")

</div>

That’s achieved by understanding how Revit thinks, once you get it, you will feel energy vibes throughout your body! 🤣 keep learning, never stop! 🙂

---

<div class="post-metadata">

**Author:** ![awilliams](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/awilliams/32/114496_2.png) [@awilliams](https://forum.dynamobim.com/u/awilliams)\
**Post date:** [April 27, 2018, 4:31pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/7 "2018-04-27T16:31:54Z")

</div>

> [@vanlion](#):
>
> for i in builtInParams:  
> if i == paramName:  
> test.append(i)

This part of your script was checking `i` (an Autodesk.Revit.DB.Parameter element) against paramName (a string) so you were returning an empty list for bip. In my revision below you’ll see I create a dictionary of the BuiltInParameters names as the keys and the BuiltInParameter elements as the values, then search the dictionary with the paramName input.

There was also a typo where you assigned `typedCatlist`, but reference `typedCatList` so the script would have failed there - you didn’t get a warning because of try/except. I usually do not add that to a script until I’ve gotten it working properly.

But even without the typo, typedCatList would not have worked as one of the arguments for ParameterFilterElement.Create method because it is expecting an iCollection. In my revision below the line `typedCatList = List[ElementId](castlst)` is creating the iCollection

Here is my revised version of your code that appears to be functioning as expected:

```
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
from System.Collections.Generic import List
doc = DocumentManager.Instance.CurrentDBDocument

cats = IN[0]
paramName = IN[1]
pValue = IN[2]
view = UnwrapElement(IN[3])
doc = DocumentManager.Instance.CurrentDBDocument
TransactionManager.Instance.EnsureInTransaction(doc)
castlst = []
for i in cats:
	castlst.append(ElementId(i.Id))

typedCatList = List[ElementId](castlst)
rules = []

builtInParams = System.Enum.GetValues(BuiltInParameter)
bipNames = []
for i in builtInParams:
	bipNames.append(str(i))
bipDict = dict(zip(bipNames,builtInParams))
bips = [bipDict.get(p, "none") for p in paramName]

TransactionManager.Instance.EnsureInTransaction(doc)

for bip in bips:
	rules.append(ParameterFilterRuleFactory.CreateLessRule(ElementId(bip), pValue, 0.001))
	filter = ParameterFilterElement.Create(doc, 'Test', typedCatList, rules)
	view.AddFilter(filter.Id)

TransactionManager.Instance.TransactionTaskDone()

OUT = view

```

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 27, 2018, 7:36pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/8 "2018-04-27T19:36:13Z")

</div>

Thanks for the help,

I had a really short time to test is. But i get the following error:

 ![filters](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/4/f49a8ea0c13bc031cde3182b4c1fd88261f64887.JPG)

And when it is working the filter will be automatic added to the VG Filters:

 ![Filter%202](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/8/2837781dc5422b3477a9ea0dd57fa023d010c59e.JPG)

Thanks again 🙂

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [April 27, 2018, 7:45pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/9 "2018-04-27T19:45:55Z")

</div>

The error is saying that the code is trying to iterate over a list but is only receiving a singleton for paramName. You either need to modify the code to only use a single parameter name or wrap your single parameter in a list before sending it into the python node.

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 27, 2018, 9:10pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/10 "2018-04-27T21:10:15Z")

</div>

Thanks!

I feel we are so close but the adding of a list gives me the following error:

 ![filters](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/a/7a44e9b997d1d00651c1dc27584f0f09386789cf.JPG)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [April 27, 2018, 9:38pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/11 "2018-04-27T21:38:43Z")

</div>

That might be from`"none"` in like 36. You could try changing it to `None`.  
Otherwise I’d suggest outputting some of your variables to make sure they’re return what you expect.

---

<div class="post-metadata">

**Author:** ![awilliams](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/awilliams/32/114496_2.png) [@awilliams](https://forum.dynamobim.com/u/awilliams)\
**Post date:** [April 27, 2018, 9:41pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/12 "2018-04-27T21:41:27Z")

</div>

This is the set up I tested with that works with the code provided above  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/2/e250799737561c196ccf4df2ee390821fac150bf.png)

---

<div class="post-metadata">

**Author:** ![awilliams](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/awilliams/32/114496_2.png) [@awilliams](https://forum.dynamobim.com/u/awilliams)\
**Post date:** [April 27, 2018, 9:42pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/13 "2018-04-27T21:42:51Z")

</div>

I see whats wrong - you are inputting a BuiltInParameter _element_ output by your Python script beforehand, so yes for the dictionary it is returning none because it is expecting a search string. Input the BuiltInParameter as a string

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 28, 2018, 7:08am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/14 "2018-04-28T07:08:00Z")

</div>

Thanks!!

This is helping me a lot to understand python. I’m now on holiday. So i Will test it when i’m back and will let you know if it’s finally working on my pc 🙂

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [April 30, 2018, 1:55pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/15 "2018-04-30T13:55:29Z")

</div>

Now I see why you were using `"none"` 🤣

---

<div class="post-metadata">

**Author:** ![awilliams](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/awilliams/32/114496_2.png) [@awilliams](https://forum.dynamobim.com/u/awilliams)\
**Post date:** [April 30, 2018, 3:30pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/16 "2018-04-30T15:30:55Z")

</div>

@Nick_Boyts that was a bit my fault for not looking closely enough at the screen capture and only looking at the script; this part in the original script lead me to think it was meant to be input with strings:

> [@vanlion](#):
>
> def GetBuiltInParam(paramName):  
> builtInParams = System.Enum.GetValues(BuiltInParameter)  
> test =   
> for i in builtInParams:  
> if i == paramName:  
> test.append(i)  
> else:  
> pass  
> return test

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 30, 2018, 5:52pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/17 "2018-04-30T17:52:58Z")

</div>

Some question to learn dynamo in combination with phyton: are there some good sites/ guides to learn it better?

I understand some of the basics but not if you need some more complex coding 😅

---

<div class="post-metadata">

**Author:** ![Jonathan.Olesen](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jonathan.olesen/32/44242_2.png) [@Jonathan.Olesen](https://forum.dynamobim.com/u/Jonathan.Olesen)\
**Post date:** [April 30, 2018, 5:53pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/18 "2018-04-30T17:53:54Z")

</div>

This class is quite nice to get started:

> **[Untangling Python: A Crash Course on Dynamo‘s Python Node](https://www.autodesk.com/autodesk-university/class/Untangling-Python-Crash-Course-Dynamos-Python-Node-2017)**
>
> This class will walk through the basic concepts involved in usingPython within the Dynamo Environment.We will cover some basic Python concepts that are needed to write a few code samples,as well as explain in detail all the boiler plate and import...

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [April 30, 2018, 5:56pm UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/19 "2018-04-30T17:56:59Z")

</div>

Nice 👍🏻

Nice to have a forum with such good help!

---

<div class="post-metadata">

**Author:** ![vanlion](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/vanlion/32/46722_2.png) [@vanlion](https://forum.dynamobim.com/u/vanlion)\
**Post date:** [May 9, 2018, 9:08am UTC](https://forum.dynamobim.com/t/created-filter-to-view/21377/20 "2018-05-09T09:08:42Z")

</div>

Hi,

The code is working good. I want to make a modification so you can add the filter to more than one view:

![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/1/0170f9df0db5e7c4b18bca0722aa8bfdb3dc4154.JPG)

Would this be possible?

[Next page](https://forum.dynamobim.com/t/created-filter-to-view/21377.md?page=2)
