‘FilteredElementCollector’ object has no attribute ‘BuiltInParameter’

I’m trying to filter element with Type Parameter “Assembly Code” but i’m getting an error ‘filteredelementcollector object has no attribute BuiltInParameter’.
Can anybody help me with this code?

def FilterElements (elements, zoekstring):
	filtered_elements = set()
	for ele in elements:
		code = ele.get_Parameter(BuiltInParameter.UNIFORMAT_CODE).AsString()
#		code = ele.LookupParameter("Assembly Code").AsString()
#		code = [ele.LookupParameter('Assembly Code').AsString() for ele in elements]
		if code == zoekstring:
			filtered_elements.add(ele)

elements = FilteredElementCollector(doc)\
    .OfCategory(BuiltInCategory.OST_StructuralFraming)\
    .WhereElementIsElementType().ToElements()
output = FilterElements(elements, "28")

You used a set() in your function just to filter out the type name but you don’t need that, when you get the type name you will automatically get all the unique values.

Try to make sense of the code below, I’m not sure what you want to do with the searched element but you can modify according to your needs.

def filter_elements(element_lst, search_string, replacement_string):
    """ will change the value if successful else no change """
    with Transaction(doc, __title__) as t:
        t.Start()
        for el in element_lst:
            assem_code_param = el.get_Parameter(BuiltInParameter.UNIFORMAT_CODE)
            if search_string == assem_code_param.AsString():
                assem_code_param.Set(replacement_string)
        t.Commit()


all_elements = FilteredElementCollector(doc).\
    OfCategory(BuiltInCategory.OST_StructuralFraming).\
    WhereElementIsElementType().\
    ToElements()
filter_elements(all_elements, 'AA_B2', 'CC_B1')

Hi @Martin,
Are you sure this is the exact code you’re running?
The error message tells me that you’re missing a parenthesis and did somethin like filterelementcolletcor.BuiltInParameter.
It would be great to see the full stack trace of the error to help you further.

Anyway, instead of doing a manual filter looping on the elements, you can use the WherePasses method with the ElementParameterFilter

You can also use the pyrevit.revit.db.query.get_elements_by_param_value function

Sorry for the late answer. I’m very busy and right now (11 a.m.) on my work. I’ll look at it in the evening.

A few comments
The function has no return
Backslashes are not the recommended way to wrap a line in python

If you’re trying to filter by parameter values use the ParameterFilterRuleFactory class

Something like this

def param_filter(cat, param, zoekstring):
    param_id = ElementId(param)
    pfrf = ParameterFilterRuleFactory.CreateEqualsRule(param_id, zoekstring)
    epf = ElementParameterFilter(pfrf)

    return (
        FilteredElementCollector(doc)
        .OfCategory(cat)
        .WhereElementIsElementType()
        .WherePasses(epf)
        .ToElements()
    )


output = param_filter(
    BuiltInCategory.OST_StructuralFraming,
    BuiltInParameter.UNIFORMAT_CODE,
    "28"
)
1 Like

Yes! That’s what I was looking for. :partying_face:
Thank you very much.

1 Like