過濾器過濾元素:
- 創建過濾收集器
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 }