Revit二次开发--获取门窗数量

1.在建筑物中,获取所有的门窗数量

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using System.Windows.Forms;

namespace GetAllWindows
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class GetAllWindows : IExternalCommand
{
public Autodesk.Revit.UI.Result Execute(ExternalCommandData CommandData, ref string messages, ElementSet elements)
{
UIApplication uiApp = CommandData.Application;
Autodesk.Revit.ApplicationServices.Application app = uiApp.Application;
Document doc = uiApp.ActiveUIDocument.Document;

        //获得所有窗户
        FilteredElementCollector collector = new FilteredElementCollector(doc);
        //创建一个收集器
        collector.OfClass(typeof(FamilyInstance)).OfCategory(BuiltInCategory.OST_Windows);
        IList<Element> lists = collector.ToElements();
        string strNsg = string.Format("There are {0} windows in current model", lists.Count);
        MessageBox.Show(strNsg);

        //过滤来获得所有的门
        FilteredElementCollector collector2 = new FilteredElementCollector(doc);
        ElementClassFilter classFilter = new ElementClassFilter(typeof(FamilyInstance));
        ElementCategoryFilter catFilter = new ElementCategoryFilter(BuiltInCategory.OST_Doors);
        LogicalAndFilter logicalFilter = new LogicalAndFilter(classFilter, catFilter);
        collector2.WherePasses(logicalFilter);
        IList<Element> list2 = collector2.ToElements();
        strNsg = string.Format("There Area {0} doors in current mode", list2.Count);

        MessageBox.Show(strNsg);
        return Autodesk.Revit.UI.Result.Succeeded;
    }
}

}
Revit二次开发--获取门窗数量_第1张图片
Revit二次开发--获取门窗数量_第2张图片

2.获取一层的门窗数量

你可能感兴趣的:(Class)