# Dynamo Python: FilterElementCollector(doc) by Parameter exists in elements

**URL:** <https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098>\
**Category:** Developers\
**Tags:** revit, python, dynamo\
**Created:** [May 2, 2020, 9:45am UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098 "2020-05-02T09:45:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashwani.kumar1](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@ashwani.kumar1](https://forum.dynamobim.com/u/ashwani.kumar1)\
**Post date:** [May 2, 2020, 9:45am UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/1 "2020-05-02T09:45:21Z")

</div>

I’m trying to filter out all elements from by active document in Dynamo python by parameter name id it exists in the elements.

Heres my Python code:

```
# Load the Python Standard and DesignScript Libraries
import sys
import clr 

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

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

def get_parameter_value_by_name(find, element, parameterName):
	if str(find) == element.LookupParameter(parameterName).AsString():
		return element

	
doc = DocumentManager.Instance.CurrentDBDocument

find= IN[0]
# 'find' contains the value of parameters, based on this we need to filter out the elements

elem = FilteredElementCollector(doc).WhereElementIsNotElementType().ToElements()
#All element in document (or I say Model) 

elements = []

# Place your code below this line
for i in find:
	for j in elem:
		try:
			elements.append(get_parameter_value_by_name(i, j, "JB"))
		except:
			pass
	continue
# Assign your output to the OUT variable.
OUT = elements

```

Didn’t know a lot about Revit API, I think I’m writing something wrong didn’t figure out where and what ?

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [May 2, 2020, 12:00pm UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/2 "2020-05-02T12:00:59Z")

</div>

Hi @ashwani.kumar1

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/f/7fb720681401fb795a54b78a2b4ffa0a9d1d04ff.png)

```
import sys
import clr 

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

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

def get_parameter_value_by_name(find, element, parameterName):
	if str(find) == element.LookupParameter(parameterName).AsString():
		return element

	
doc = DocumentManager.Instance.CurrentDBDocument

find= IN[0]
# 'find' contains the value of parameters, based on this we need to filter out the elements

elem = FilteredElementCollector(doc).WhereElementIsNotElementType().ToElements()
#All element in document (or I say Model) 

elements = []

# Place your code below this line
for i in elem:
	try:
		elements.append(get_parameter_value_by_name(find, i, "Comments"))
	except:
		pass
	
# Assign your output to the OUT variable.
OUT = filter(None, elements)
```

---

<div class="post-metadata">

**Author:** ![ashwani.kumar1](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@ashwani.kumar1](https://forum.dynamobim.com/u/ashwani.kumar1)\
**Post date:** [May 2, 2020, 12:28pm UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/3 "2020-05-02T12:28:04Z")

</div>

Thanks @Kulkul,

I suppose haven’t asked my question properly or in a right way.

Earlier, with this script I already got the elements that having those values as an output. But in addition to that I also need the remaining elements as well , who has ‘JB’ parameters as in its properties , weather its contain bank value.

And I suppose I can just add one more blank item in my ‘find’ input list.

```
find= IN[0]+[" "]
#But its no good, all elements not appeared having 'JB' parameter

```

Hope this time, it will be clear. In your case, the same goes for ‘Comments’

Or I would say, I need to filter out the elements by parameter names (‘JB’) if exists not by its value.

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [May 3, 2020, 7:19am UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/4 "2020-05-03T07:19:09Z")

</div>

> [@ashwani.kumar1](#):
>
> I need to filter out the elements by parameter names (‘JB’) if exists not by its value.

?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/c/7c1bcfd5c52d9cbd937598e9d3e336304e78aeb6.png)

---

<div class="post-metadata">

**Author:** ![ashwani.kumar1](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@ashwani.kumar1](https://forum.dynamobim.com/u/ashwani.kumar1)\
**Post date:** [May 3, 2020, 7:31am UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/5 "2020-05-03T07:31:20Z")

</div>

Yeah, that exactly right, What did you do ?

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [May 3, 2020, 12:04pm UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/6 "2020-05-03T12:04:17Z")

</div>

> [@ashwani.kumar1](#):
>
> What did you do ?

```
for e in elem:
	try:
		params = e.Parameters
		paramNames = [i.Definition.Name for i in params]
		if param in paramName:
			elements_contains_param.append(e)

```

---

<div class="post-metadata">

**Author:** ![ashwani.kumar1](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@ashwani.kumar1](https://forum.dynamobim.com/u/ashwani.kumar1)\
**Post date:** [May 3, 2020, 12:23pm UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/7 "2020-05-03T12:23:01Z")

</div>

Thanks, @Kulkul. This resolves the Issue, What I missed the method and i.e. `Definition.Name`. Thanks this really helps.

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [May 3, 2020, 12:39pm UTC](https://forum.dynamobim.com/t/dynamo-python-filterelementcollector-doc-by-parameter-exists-in-elements/50098/8 "2020-05-03T12:39:04Z")

</div>

> [@ashwani.kumar1](#):
>
> This resolves the Issue

@ashwani.kumar1 Mark the post as solved.
