フィルタを使用して、特定の条件を満たしている要素のみを選択できます。要素フィルタの作成と使用の詳細については、「要素のコレクションを反復する」を参照してください。
この例は、ドキュメント内のすべてのドアを取得し、ドア要素のリストを返します。
|
コード領域 2-8: フィルタした要素を取得 |
public ICollection<Element> CreateLogicAndFilter(Autodesk.Revit.DB.Document document)
{
// Find all door instances in the project by finding all elements that both belong to the door
// category and are family instances.
ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance));
// Create a category filter for Doors
ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
// Create a logic And filter for all Door FamilyInstances
LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter);
// Apply the filter to the elements in the active document
FilteredElementCollector collector = new FilteredElementCollector(document);
IList<Element> doors = collector.WherePasses(doorInstancesFilter).ToElements();
return doors;
}
|