Revit API は Revit ドキュメントの要素をフィルタリング、走査するためのメカニズムが用意されています。これは、ドキュメント内の壁やドアといった一連の関連する要素を取得するための最適な方法です。また、フィルタを使用すると、特定のサイズのすべての梁といった非常に限定された要素のセットを見つけるのにも使用できます。
指定したフィルタを通過する要素を取得するための基本的な手順は次のとおりです。
次の例は、ドキュメント内の要素のフィルタと繰り返しのための基本的な手順を表します。
|
コード領域 6-1: 要素のフィルタリングを使用してドキュメント内のすべての壁のインスタンスを取得 |
// Find all Wall instances in the document by using category filter
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
// Apply the filter to the elements in the active document
// Use shortcut WhereElementIsNotElementType() to find wall instances only
FilteredElementCollector collector = new FilteredElementCollector(document);
IList<Element> walls =
collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();
String prompt = "The walls in the current document are:\n";
foreach (Element e in walls)
{
prompt += e.Name + "\n";
}
TaskDialog.Show("Revit", prompt);
|