Is there a method of creating a slow filter with FilteredElementCollector on element name?

Is there a method of creating a slow filter with FilteredElementCollector on element name?

vhh7Z3D2
Contributor Contributor
1,692 Views
20 Replies
Message 1 of 21

Is there a method of creating a slow filter with FilteredElementCollector on element name?

vhh7Z3D2
Contributor
Contributor

I have a lot of code where filtering is done on the element name like:

AssemblyInstance assemblyInstance = new FilteredElementCollector(doc)
    .OfClass(typeof(AssemblyInstance))
    .Cast<AssemblyInstance>()
    .Where(assembly => assembly.Name == "SE51")
    .FirstOrDefault();

In previous versions of the API it seems like it was possible to make a slow filter on element name as explained here by using either of the these builtinparameters as filters:

 

  • BuiltInParameter.ALL_MODEL_NAME
  • BuiltInParameter.DATUM_TEXT
  • BulitInParameter.ELEM_NAME_PARAM

Example:

FilterRule rule = ParameterFilterRuleFactory.CreateEqualsRule(new ElementId(BuiltInParameter.DATUM_TEXT), "SE51");
ElementParameterFilter filter = new ElementParameterFilter(rule);

AssemblyInstance assemblyInstance = new FilteredElementCollector(doc)
    .OfClass(typeof(AssemblyInstance))
    .WherePasses(filter)
    .Cast<AssemblyInstance>()
    .FirstOrDefault();

However this does not work in 2022 and up.

Is there a way in the current API to make a filter on the name of an element?

0 Likes
Accepted solutions (1)
1,693 Views
20 Replies
Replies (20)
Message 21 of 21

jeremy_tammik
Alumni
Alumni

> ... I do need the document though, so it will have to added as a parameter since there is no way to get it from the collector...
   
Well, actually, that statement is true if and only if the collector collects zero elements, in which case the result is empty anyway. If it collects one or more elements, you can query each one of those elements for its document, and they will all be the same, so you can just use the first one encountered. Can the extraction of that document be included in an extension method? I do believe it can...

  

You could also add a few filters, call FirstElement().Document, and then add more filters afterwards.
     

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes