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

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 ?

Hi @ashwani.kumar1

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)

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.

?

Yeah, that exactly right, 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)
1 Like

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

@ashwani.kumar1 Mark the post as solved.