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

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 1408|回复: 35
打印 上一主题 下一主题

ElementParameterFilter: Using FilterElementIdRule to Filter Element Parameters i

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

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

积分
12408

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-9 12:17:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Let us continue to talk about the particular slow filter in Revit API, ElementParameterFilter.   
Let’s look at how to use the FilterElementIdRule filter rule to filter element id type element parameters in this article. Supposing we’d like to find all rooms with the Phase Created parameter as a specific phase, what shall we do?
The following code does so in C#:
public static ICollection<ElementId> GetWallsInPhase(RvtDocument doc, Phase phase)
{
    ParameterValueProvider provider = new ParameterValueProvider(new ElementId((int)BuiltInParameter.PHASE_CREATED));
    FilterElementIdRule rule1 = new FilterElementIdRule(provider, new FilterNumericEquals(), phase.Id);
    ElementParameterFilter filter1 = new ElementParameterFilter(rule1);
    return
        (new FilteredElementCollector(doc))
        .OfClass(typeof(Wall))
        .WherePasses(filter1)
        .ToElementIds();
}


A few highlights about the code:
• An ElementParameterFilter needs a filter rule, the FilterElementIdRule in this case.
• The FilterElementIdRule needs a parameter value provider (ParameterValueProvider) and a filter rule evaluator (FilterStringRuleEvaluator), specifically the FilterNumericEquals here.
• Do not feel surprised that the FilterNumericEquals evaluator also works with the FilterElementIdRule as the ElementId is effectively nothing more than an integer value.
• The ParameterValueProvider needs an argument of parameter, as the phase created parameter BuiltInParameter.PHASE_CREATED 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 PHASE_CREATED of the BuiltInParameter enumerator is the right one to use?
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#:

Phase phase = CachedDoc.Phases.get_Item(0);
ICollection<ElementId> ids = GetWallsInPhase(CachedDoc, phase);
TaskDialog.Show("ElementParameterFilter Test", string.Format("{0} walls are in the phase created {1}.", ids.Count, phase.Name));

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

11

主题

846

帖子

1772

积分

BIM经理

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

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

6

主题

853

帖子

1347

积分

BIM经理

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

积分
1347
推荐
发表于 2014-3-18 11:06:48 | 只看该作者
(*^__^*) 嘻嘻……

5

主题

884

帖子

1541

积分

BIM经理

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

积分
1541
推荐
发表于 2014-3-11 10:30:56 | 只看该作者
谢谢BIM大神…

11

主题

846

帖子

1772

积分

BIM经理

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

积分
1772
11F
发表于 2014-3-13 12:15:07 | 只看该作者
(*^__^*) 嘻嘻……

13

主题

840

帖子

1580

积分

BIM经理

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

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

本版积分规则

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

GMT+8, 2024-11-30 14:02

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

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