Revit常用的元素過濾方法

過濾器過濾元素

  • 創建過濾收集器
Document document = revit.Application.ActiveUIDocument.Document;
FilteredElementCollector collector = new FilteredElementCollector(document);  
  • 過濾元素
  1. 快速過濾
    collector.OfCategory(BuiltInCategory.OST_Walls).ofClass(typeof(FamilyInstance))
    OfCategory過濾類別,包括FamilySymbol及FamilyInstance,先通過OfCategory進行過濾可以提高效率,通過OfClass可以獲取實例或者類型。
  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
}

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章