EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

萧闫子 发表于 2014-1-9 12:16:55

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.

教父 发表于 2014-6-12 09:42:48

路过!!!
不发表意见……

风浪子 发表于 2014-2-20 15:04:25

(*^__^*) 嘻嘻……

孙雅 发表于 2014-6-12 09:37:55

(*^__^*) 嘻嘻……

AK47 发表于 2014-3-10 17:21:25

顶!!!!!!!!!!

老鼠仔CH 发表于 2014-3-11 10:28:39

顶!!!!!!!!!!

车晶晶 发表于 2014-3-11 10:31:01

了解下BIM.....

We晕晕 发表于 2014-3-11 10:35:02

看看啥…………

ben7 发表于 2014-3-11 10:36:53

谢谢BIM大神…

一梦千寻 发表于 2014-3-13 12:00:14

顶!!!!!!!!!!

gba8297517 发表于 2014-3-13 12:04:52

顶起来…………

入樽 发表于 2014-3-13 12:11:08

顶!!!!!!!!!!

烈火ivk 发表于 2014-3-13 12:14:56

顶!!!!!!!!!!

千里独行 发表于 2014-3-13 12:26:52

顶!!!!!!!!!!

矮矮 发表于 2014-3-13 12:30:28

顶!!!!!!!!!!

静儿 发表于 2014-3-14 10:56:25

顶......
楼下跟上.....

zj1345 发表于 2014-3-14 11:01:36

顶......
楼下跟上.....
页: [1] 2 3 4
查看完整版本: ElementParameterFilter: Using SharedParameterApplicableRule to Filter Element Pa