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