欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

过滤器的使用

程序员文章站 2024-02-26 18:49:04
...
 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;  //取得文档
            UIApplication uiApp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application;             //取得应用程序
            FilteredElementCollector elementcollects = new FilteredElementCollector(revitDoc );//创建一个收集器
             //创建一个过滤器
 **ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);            
 elementcollects = elementcollects.WherePasses(elementCategoryFilter);**
	            MessageBox.Show(elementcollects.Count().ToString());
	            foreach (Element  item in elementcollects)
	            {
	                MessageBox.Show(item.Name);
	            }

  	 return Result.Succeeded;
	   }

过滤器的使用
以上是筛选出了 组类型和族实例 注意 墙体没有族实例

 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;  //取得文档
            UIApplication uiApp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application;             //取得应用程序
            **FilteredElementCollector elementcollects = new FilteredElementCollector(revitDoc );//创建一个收集器
                                                                                               //创建一个过滤器
            ElementClassFilter elementClassFilter = new ElementClassFilter(typeof(Wall));**

            elementcollects = elementcollects.WherePasses(elementClassFilter);
                                                                                  /*.OfClass(typeof(FamilyInstance));*/
            MessageBox.Show(elementcollects.Count().ToString());
            foreach (Element  item in elementcollects)
            {
                MessageBox.Show(item.Name);
            }

            return Result.Succeeded;
        }

过滤器的使用
上面只是筛选出了墙的“实例”

namespace ClassLibrary1
{
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;  //取得文档
            UIApplication uiApp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application;             //取得应用程序
            FilteredElementCollector elementcollects = new FilteredElementCollector(revitDoc );//创建一个收集器
                    //创建一个过滤器
            **ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
            elementcollects = elementcollects.WherePasses(elementCategoryFilter);**/*.OfClass(typeof(FamilyInstance));*/
            MessageBox.Show(elementcollects.Count().ToString());
            foreach (Element  item in elementcollects)
            {
                MessageBox.Show(item.Name);
            }
            return Result.Succeeded;
        }
    }
}

过滤器的使用
以上筛选出了族类型 和族实例

namespace ClassLibrary1
{
    [Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Document revitDoc = commandData.Application.ActiveUIDocument.Document;  //取得文档
            UIApplication uiApp = commandData.Application;
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Autodesk.Revit.ApplicationServices.Application revitApp = commandData.Application.Application;             //取得应用程序
            FilteredElementCollector elementcollects = new FilteredElementCollector(revitDoc );//创建一个收集器
                                                                                       //创建一个过滤器
            **ElementCategoryFilter elementCategoryFilter = new ElementCategoryFilter(BuiltInCategory.OST_StructuralFraming);
            elementcollects = elementcollects.WherePasses(elementCategoryFilter).OfClass(typeof(FamilyInstance));**
            MessageBox.Show(elementcollects.Count().ToString());
            foreach (Element  item in elementcollects)
            {
                MessageBox.Show(item.Name);
            }

            return Result.Succeeded;
        }
    }

过滤器的使用
以上就是筛选出了 所有的梁的族实例