ElementParameterFilter: Using FilterIntegerRule to Filter Element Parameters in
Let us continue to talk about the particular slow filter in Revit API, ElementParameterFilter.Let’s look at how to use the FilterIntegerRule filter rule to filter integer type element parameters in this article. Supposing we’d like to find all walls which bind some rooms, what shall we do?
The following code does so in C#:public static ICollection<ElementId> GetWallsRoomBound(RvtDocument doc)
{
ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.WALL_ATTR_ROOM_BOUNDING));
FilterIntegerRule rule = new FilterIntegerRule(provider, new FilterNumericEquals(), 1);
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 FilterIntegerRule in this case.
• The FilterIntegerRule needs a parameter value provider (ParameterValueProvider) and a filter rule evaluator (FilterNumericRuleEvaluator), specifically the FilterNumericEquals.
• The FilterIntegerRule also needs a value for the integer parameter to compare with.
• The ParameterValueProvider needs an argument of parameter, as the wall room bounding parameter BuiltInParameter. WALL_ATTR_ROOM_BOUNDING in this case.
• The parameter is represented by an ElementId, which is the numeric value of the specified BuiltInParameter.
• 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 WALL_ATTR_ROOM_BOUNDING of the BuiltInParameter enumerator is the right one to use as there are tons of built-in parameters there?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 CoderTo use the method is very straightforward. Here is some test code in C#:…
ICollection<ElementId> ids = GetWallsRoomBound(CachedDoc);
TaskDialog.Show("ElementParameterFilter Test", string.Format("{0} walls are binding rooms.", ids.Count));
…
路过!!!
不发表意见……
路过!!!
不发表意见……
路过!!!
不发表意见……
路过!!!
帮顶……
顶!!!!!!!!!!
了解下BIM.....
谢谢!!!
帮顶……
非常感谢!!
非常感谢!!
顶!!!!!!!!!!!!!!!!!!!!!!!!!
顶起来………… 顶!!!!!!!!!! 顶......
楼下跟上..... (*^__^*) 嘻嘻……