EaBIM
标题: ElementSlowFilter-慢速过滤器 [打印本页]
作者: 萧闫子 时间: 2014-1-9 12:29
标题: ElementSlowFilter-慢速过滤器
We talked about the quick filters (ElementQuickFilter) in the previous post. In this article, we will discuss something about the slow filters (ElementSlowFilter).
Slow filters include:
• RoomFilter
• RoomTagFilter
• AreaFilter
• AreaTagFilter
• CurveElementFilter
• ElementLevelFilter
• ElementParameterFilter
• FamilyInstanceFilter
• SpaceFilter
• SpaceTagFilter
• PrimaryDesignOptionMemberFilter
• FamilyStructuralMaterialTypeFilter
• StructuralInstanceUsageFilter
• StructuralMaterialTypeFilter
• StructuralWallUsageFilter
We have discussed the differences and their similarities between the slow filters and the quick filters and even in the same group, so we will not repeat here. Now let’s look at a specific case, how to create some filters and a final FilteredElementCollector to collect all rooms, areas, spaces and their tags back, and they should be in the primary design option.
To achieve this goal, quite a few different kinds of slow filters seem necessary: RoomFilter, RoomTagFilter, AreaFilter, AreaTagFilter, SpaceFilter, SpaceTagFilter and PrimaryDesignOptionMemberFilter. We use them in the following code example to demonstrate slow filters:
public static List<Element> FindRoomsAreasSpacesAndTheirTags(RvtDocument doc)
{
List<Element> list = new List<Element>();
FilteredElementCollector finalCollector = new FilteredElementCollector(doc);
RoomFilter filter1 = new RoomFilter();
finalCollector.WherePasses(filter1);
RoomTagFilter filter2 = new RoomTagFilter();
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter2));
AreaFilter filter3 = new AreaFilter();
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter3));
AreaTagFilter filter4 = new AreaTagFilter();
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter4));
SpaceFilter filter5 = new SpaceFilter();
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter5));
SpaceTagFilter filter6 = new SpaceTagFilter();
finalCollector.UnionWith((new FilteredElementCollector(doc)).WherePasses(filter6));
PrimaryDesignOptionMemberFilter filter7 = new PrimaryDesignOptionMemberFilter(false);
finalCollector.IntersectWith((new FilteredElementCollector(doc)).WherePasses(filter7));
list = finalCollector.ToList<Element>();
return list;
}
The call to the method and some test code look like:
List<Element> elements = ElementFinder.FindRoomsAreasSpacesAndTheirTags(CachedDoc);
MessageBox.Show(string.Format("{0} rooms, areas, spaces and their tags in the PrimaryDesignOption are found in the model.", elements.Count.ToString()));
By the way, the above code likely will report zero elements found in some models since those rooms, areas, spaces and their tags may not be in the primary design option at all. So as to exercise the PrimaryDesignOptionMemberFilter, please make sure some elements are really using it.
Last but not least, the same task can be completed by some other filters, preferably quick filters like the ElementCategoryFilter and/or the ElementClassFilter. And even for the seemingly very special PrimaryDesignOptionMemberFilter, the ElementParameterFilter one can be a replacement, I believe. The alternative (maybe better/quicker) approach will not be demonstrated in detail here, but you can take it as an assignment if you like.
Do not worry about all the different kinds of filters and their arguments, quick or slow, theRevitAddinWizardwill help you generate any combinations of the filters and their arguments in a moment.
作者: 老朽 时间: 2014-2-20 14:59
顶......
楼下跟上.....
欢迎光临 EaBIM (https://eabim.net/) |
Powered by Discuz! X3.2 |