この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:2
ページ更新者:T
更新日時:2020-05-03 17:12:24

タイトル: 要素フィルターの使い方
SEOタイトル: 【Revit API】要素フィルターの使い方

この記事の要点
  • Revit API (C#) で要素フィルター(特定カテゴリの要素のみ抽出)を使う方法
  • 基本: new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Walls)
  • クラス指定: .OfClass(typeof(Wall))
  • 結果取得: .ToElements() または .ToElementIds()

 

前提

C#(他言語の場合は適宜読み替えてください。)

 

実装

以下の実装例は壁の要素のみ抽出している。

using System;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using System.Collections.Generic;

namespace TestTool
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class TestTool : IExternalCommand
    {
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
            ref string message, ElementSet elements)
        {

            UIDocument uidoc = commandData.Application.ActiveUIDocument;

            Document document = uidoc.Document;

 

            ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);

            FilteredElementCollector collector = new FilteredElementCollector(document);

            IList<Element> walls = collector.WherePasses(filter).WhereElementIsNotElementType().ToElements();

 

            String prompt = "The walls in the current document are:\n\t";

            foreach (Element e in walls)
            {
                prompt += "ID: " + e.Id + ", Name: " + e.Name + "\n\t";
            }

            TaskDialog.Show("Revit", prompt);

            return Autodesk.Revit.UI.Result.Succeeded;
        }
    }
}

 

 

以下、ツールの実行結果例。