二開常用的元素過濾方法
阿新 • • 發佈:2020-10-27
過濾器過濾元素:
- 建立過濾收集器
Document document = revit.Application.ActiveUIDocument.Document; FilteredElementCollector collector = new FilteredElementCollector(document);
- 過濾元素
- 快速過濾
collector.OfCategory(BuiltInCategory.OST_Walls).ofClass(typeof(FamilyInstance))
OfCategory過濾類別,包括FamilySymbol及FamilyInstance
- 通用過濾
LogicalAndFilter doorInstancesFilter =new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); FilteredElementCollector collector = new FilteredElementCollector(document); ICollection<ElementId> doors = collector.WherePasses(doorInstancesFilter).ToElementIds();
框選構件並篩選構件
publicclass 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(newWallFilter(), "請選擇牆"); foreach (Element element in elements) { // do something }