Revit常用的元素过滤方法
过滤器过滤元素:
- 创建过滤收集器
Document document = revit.Application.ActiveUIDocument.Document; FilteredElementCollector collector = new FilteredElementCollector(document);
- 过滤元素
- 快速过滤
collector.OfCategory(BuiltInCategory.OST_Walls).ofClass(typeof(FamilyInstance))
OfCategory过滤类别,包括FamilySymbol及FamilyInstance,先通过OfCategory进行过滤可以提高效率,通过OfClass可以获取实例或者类型。
- 通用过滤
LogicalAndFilter doorInstancesFilter =new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); FilteredElementCollector collector = new FilteredElementCollector(document); ICollection<ElementId> doors = collector.WherePasses(doorInstancesFilter).ToElementIds();
框选构件并筛选构件
public class WallFilter : ISelectionFilter { public bool AllowElement(Element element) { if (element is Wall) { return true; } return false; } public bool AllowReference(Reference refer, XYZ point) { return false; } } // code in command IList<Element> elements = uiDoc.Selection.PickElementsByRectangle(new WallFilter(), "请选择墙"); foreach (Element element in elements) { // do something }
工欲善其事必先利其器!!!