Revit .NET API provides quite some classes and methods to filter elements and parameters. FilterRule, ElementParameterFilter and FilteredElementCollector.WherePasses() are among those pretty important ones.
They can be used to filter out some elements from a document with some parameter criteria such as name and value, e.g. wall length is greater than something.
A simple request comes out actually: is it possible to use them to find elements with a particular parameter no matter what value it may have in each element?
The answer is: yes, possible, but not that straightforward. Some workaround has to be applied. For example, if we want to find all elements with the Cost parameter, here we go.
Find the built-in parameter with coders in Revit .NET API Wizard or make some guess once in a while and do some experiences here and there. Let's say it is ALL_MODEL_COST.
Create two opposite filter rules with methods inside ParameterFilterRuleFactory such as CreateGreaterOrEqualRule and CreateLessOrEqualRule.
Create an ElementParameterFilter from the two rules.
Create an instance of FilteredElementCollector and call its WherePasses() method with the ElementParameterFilter instance passed in.
That is it! Enjoy!
Hi,
Do you have a code snippet to illustrate it?
Posted by: JeanMarcCouffin | 04/29/2020 at 08:02 AM