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:
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?
Solved! Go to Solution.
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:
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?
Solved! Go to Solution.
Solved by vhh7Z3D2. Go to Solution.
> ... 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.
> ... 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.
Can't find what you're looking for? Ask the community or share your knowledge.