Area collector empty (RevitPythonShell)

Area collector empty (RevitPythonShell)

g_sicre
Contributor Contributor
767 Views
3 Replies
Message 1 of 4

Area collector empty (RevitPythonShell)

g_sicre
Contributor
Contributor

Hello,

 

I am working on a code to grab all built areas for each home in a single-family project, although the dictionary values where areas should be stored it is empty.

 

Could you tell me what am I doing wrong? I leave the code below.

 

Thank you.

 

# Obtención de areas por vivienda

areas = FilteredElementCollector(doc)\
        .OfCategory(BuiltInCategory.OST_Areas)
        
for i in areas:
    param_portal_id = i.LookupParameter('Portal').Id
    break

for i in areas:
    param_nombre_id = i.LookupParameter('Nombre').Id
    break

param_pro_portal = ParameterValueProvider(param_portal_id)
param_pro_nombre = ParameterValueProvider(param_nombre_id)

param_contains = FilterStringContains()
param_equals = FilterStringEquals()

filter_rule_jardin = FilterStringRule(param_pro_nombre, param_contains, 'Jard'False)
ft_sup_jardin = ElementParameterFilter(filter_rule_jardin)

filter_rule_terraza = FilterStringRule(param_pro_nombre, param_contains, 'Terraza'False)
ft_sup_terraza = ElementParameterFilter(filter_rule_terraza)

areas_viv_dict = {}     # Diccionario con todas las superficies construidas por vivienda con filtros
                        # (key = gate, value = areas list)

for i in range(148😞
    filter_rule = FilterStringRule(param_pro_portal, param_contains, str(i), True)
    ft_sup = ElementParameterFilter(filter_rule)  
    areas_viv = areas\
                .WherePasses(ft_sup)\
                .WherePasses(ft_sup_jardin)\
                .WherePasses(ft_sup_terraza)\
                .ToElements()
    areas_viv_dict[i] = areas_viv
0 Likes
Accepted solutions (1)
768 Views
3 Replies
Replies (3)
Message 2 of 4

jeremytammik
Autodesk
Autodesk

Yes. I see the problem.

 

areas is a filtered element collector. Every time to add a call to WherePasses to it, a new filter is added. You are adding WherePasses filters to it in a loop, so the elements are being more and more strongly filtered, until (very rapidly) none are left that can pass the filters.

  

Solutions:

  

  • Either instantiate a new filtered element collector for each pass through the loop,
  • Or create a Boolean OR clause of the different WherePasses filters and apply the OR once only.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 4

g_sicre
Contributor
Contributor

Hi Jeremy, 

 

thank you for the response. I have been trying both solutions but I am still stuck. However, doing some tests I have realized that something seems not to be working well with the FilterStringRule Class since for both bool value cases the result is always the same. I leave two images with the testing code.

0 Likes
Message 4 of 4

jeremytammik
Autodesk
Autodesk
Accepted solution

Yes, indeed, you are perfectly correct.

 

This issue was recently discussed here in the forum and with the Revit development team:

 

https://forums.autodesk.com/t5/revit-api-forum/class-filterstringrule-parameter-casesensitive-has-no...

 

As explained in the other thread, and as you can obviously imagine for yourself, it is easy enough to work around.

 

Sorry for the confusion, however!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes