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

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 1486|回复: 33
打印 上一主题 下一主题

ElementParameterFilter: Using SharedParameterApplicableRule to Filter Element Pa

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12406

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-9 12:16:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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.

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

16

主题

842

帖子

1377

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1377
推荐
发表于 2014-6-12 09:42:48 | 只看该作者
路过!!! 不发表意见……

12

主题

861

帖子

1353

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1353
推荐
发表于 2014-2-20 15:04:25 | 只看该作者
(*^__^*) 嘻嘻……

19

主题

878

帖子

1359

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1359
推荐
发表于 2014-6-12 09:37:55 | 只看该作者
(*^__^*) 嘻嘻……

22

主题

983

帖子

4033

积分

BIM总监

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

积分
4033
7F
发表于 2014-3-11 10:36:53 | 只看该作者
谢谢BIM大神…

11

主题

892

帖子

1455

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1455
14F
发表于 2014-3-14 10:56:25 | 只看该作者
顶......
楼下跟上.....

8

主题

792

帖子

1349

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1349
15F
发表于 2014-3-14 11:01:36 | 只看该作者
顶......
楼下跟上.....
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-27 05:27

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表