フィルタを使用して、特定の条件を満たしている要素のみを選択できます。要素フィルタの作成と使用の詳細については、「要素のコレクションを反復する」を参照してください。
この例では、ドキュメントのすべてのドアを取得して、その ID を一覧表示するダイアログが表示されます。
コード領域 2-8: フィルタした要素を取得 |
// Create a Filter to get all the doors in the document ElementClassFilter familyInstanceFilter = new ElementClassFilter(typeof(FamilyInstance)); ElementCategoryFilter doorsCategoryfilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors); LogicalAndFilter doorInstancesFilter = new LogicalAndFilter(familyInstanceFilter, doorsCategoryfilter); FilteredElementCollector collector = new FilteredElementCollector(document); ICollection<ElementId> doors = collector.WherePasses(doorInstancesFilter).ToElementIds(); String prompt = "The ids of the doors in the current document are:"; foreach(ElementId id in doors) { prompt += "\n\t" + id.IntegerValue; } // Give the user some information TaskDialog.Show("Revit",prompt); |