1. 程式人生 > 實用技巧 >二開常用的元素過濾方法

二開常用的元素過濾方法

過濾器過濾元素

  • 建立過濾收集器
Document document = revit.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(document);  
  • 過濾元素
  1. 快速過濾
    collector.OfCategory(BuiltInCategory.OST_Walls).ofClass(typeof(FamilyInstance))
    OfCategory過濾類別,包括FamilySymbol及FamilyInstance
  2. 通用過濾
    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 }