From this post on, let us check on a particular slow element filter of Revit API in more detail, ElementParameterFilter.
Let’s look at how to use the FilterDoubleRule filter rule to filter number (double) type element parameters first. Supposing we’d like to find all walls with length more than ten feet, what shall we do?
The following code does so in C#:
public static ICollection<ElementId> GetWallsLongerThan(RvtDocument doc, double w, double tolerance)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.CURVE_ELEM_LENGTH));
FilterDoubleRule rule = new FilterDoubleRule(provider, new FilterNumericGreater(), w, tolerance);
ElementParameterFilter filter = new ElementParameterFilter(rule);
return (new FilteredElementCollector(doc)).OfClass(typeof(Wall)).WherePasses(filter).ToElementIds();
}
A few highlights about the code:
• An ElementParameterFilter needs a filter rule, the FilterDoubleRule in this case.
• The FilterDoubleRule needs a parameter value provider (ParameterValueProvider) and a filter rule evaluator (FilterNumericRuleEvaluator), specifically the FilterNumericGreater here.
• The FilterDoubleRule also needs a value and a tolerance which are straightforward.
• The ParameterValueProvider needs an argument of parameter, as the wall length parameter BuiltInParameter.CURVE_ELEM_LENGTH in this case.
• The parameter is represented by an ElementId, which is the enumerator numeric value for BuiltInParameter types.
• A fast filter, ElementClassFilter, represented by its shortcut method (OfClass), is also used to narrow down the FilteredElementCollector first. It not only speeds up the search but also makes sure only walls are returned.
Curious people may ask: how did you figure out the CURVE_ELEM_LENGTH value of the BuiltInParameter enumerator is the right one to use as its name does not have anything to do with walls?
Good question! Though we still have to make some guess and do some experiment most of times to sort things like this out, a few RevitAddinCoder coders can help make the task a lot easier:
• Parameter Infoer Coder
• Parameter Categorizer Coder
• Parameter Retriever Coder
To use the method is very straightforward. Here is some test code in C#:
…
ICollection<ElementId> ids = GetWallsLongerThan(CachedDoc, 10, 10e-5);
TaskDialog.Show("ElementParameterFilter Test", string.Format("There are {0} walls )\’
longer than 10 feet.", ids.Count));
…
ElementParameterFilter Creator of RevitAddinCoder can create the code automatically in no time.
Recent Comments