ElementParameterFilter: Using SharedParameterApplicableRule to Filter Element Pa
Let us continue to talk about the particular slow filter in Revit API, ElementParameterFilter.
Let’s look at how to use the SharedParameterApplicableRule filter rule to filter out elements which have some project parameter associated with. Supposing we’d like to find all elements which have a specific project parameter, what shall we do?The following code does so in C#:public static List<IGrouping<string, Element>> GetWallsHavingProjectParameter(RvtDocument doc, string paramName)
{
SharedParameterApplicableRule rule = new SharedParameterApplicableRule(paramName);
ElementParameterFilter filter = new ElementParameterFilter(rule); return (new FilteredElementCollector(doc)).
WherePasses(filter).
GroupBy(e => e.GetType().Name).
ToList();
}
A few highlights about the code:• An ElementParameterFilter needs a filter rule, the SharedParameterApplicableRule in this case.
• The SharedParameterApplicableRule only needs a parameter name.
• The parameter should be a project parameter or bound shared parameter instead of a BuiltInParameter.
• No fast filter like ElementClassFilter is used here as it does not make sense to do so since project parameters can only be bound to some Revit whole categories or element classes rather than to a few particular element instances.To use the method is very straightforward. Here is some test code in C#:…
string sharedParameterName = "PrjParameter1";
List<IGrouping<string, Element>> list = GetWallsHavingProjectParameter(CachedDoc, sharedParameterName);
string msg1 = string.Format("{0} types of elements have the shared parameter {1}\n", list.Count, sharedParameterName);
foreach (IGrouping<string, Element> group in list)
{
msg1 += string.Format("\tCount in type {0}: {1}\n", group.Key,group.Count());
}
MessageBox.Show(msg1);
…
So in the test model, four element classes have the project parameter PrjParameter1 associated with and they are WallType, Wall, FamilyInstance, and FamilySymbol. The element count in each class is also reported.
路过!!!
不发表意见……
(*^__^*) 嘻嘻……
(*^__^*) 嘻嘻……
顶!!!!!!!!!!
顶!!!!!!!!!!
了解下BIM.....
看看啥…………
谢谢BIM大神…
顶!!!!!!!!!!
顶起来…………
顶!!!!!!!!!!
顶!!!!!!!!!! 顶!!!!!!!!!! 顶!!!!!!!!!! 顶......
楼下跟上..... 顶......
楼下跟上.....