Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

20 REPLIES 20
SOLVED
Reply
Message 1 of 21
vhh7Z3D2
846 Views, 20 Replies

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

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

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?

20 REPLIES 20
Message 21 of 21
jeremy_tammik
in reply to: vhh7Z3D2

jeremy_tammik
Autodesk
Autodesk

> ... 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

> ... 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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report