• revit二次开发之 过滤器一


            Revit通过过滤器来区分不同的元素,这些过滤器为应用程序获取不同的元素提供了方便灵活的接口。在使用过滤器的过程中,会应用到一个常用元素FilteredElementCollector类,我们称之为“收集器”,指定对应的收集器以后,再传入对用的过滤器,对需要的元素进行过滤。

    1、收集器

    常用的收集器,有以下几个:

    1.1 元素收集器,FilteredElementCollector

       通过传入文档、视图和元素集合,实现对元素进行收集。

    FilteredElementCollector collector = new FilteredElementCollector(doc);
     collector.WherePasses(new ElementClassFilter(typeof(FamilyInstance)));
    var sphereElements = from element in collector where element.Name == "sphere" select element;
    if (sphereElements.Count() == 0)
    {
                TaskDialog.Show("Error", "Sphere family must be loaded");
                return;
     }

    1.2 工作集元素收集器,FilteredWorksetCollector

       用于在工作集中,文档中过滤出指定工作集的元素,其代码如下:

    FilteredWorksetCollector col = new FilteredWorksetCollector(doc);
                _AllWorksetList = col.Where(p => p.Kind == WorksetKind.UserWorkset).OrderBy(p => p.Name).ToList();
                foreach (Workset ws in _AllWorksetList)
                {
                    checkedListBox1.Items.Add(ws.Name);
                    _SumCount++;
     }

    收集器通过方法WherePasses实现对元素的过滤。

    2、过滤器

    revit的过滤器无非三种类别:

    Autodesk.Revit.DB..::..ElementFilter
        Autodesk.Revit.DB..::..ElementLogicalFilter
        Autodesk.Revit.DB..::..ElementQuickFilter
        Autodesk.Revit.DB..::..ElementSlowFilter

    2.1 ElementQuickFilter元素快速过滤器

    名称    

    类型

    作用

    备注

    BoundingBoxContainsPointFilter

    快速过滤器

    其边界盒包含了给定点的元素

    BoundingBoxIntersectsFilter

    快速过滤器

    与指定边界盒相交的元素

    BoundingBoxIsInsideFilter

    快速过滤器

    在指定边界盒之内的元素

    ElementCategoryFilter

    快速过滤器

    通过指定的类别过滤

    ElementClassFilter

    快速过滤器 

    指定元素类进行过滤

    ElementDesignOptionFilter 

    快速过滤器

    元素的详细程度过滤

    ElementIsCurveDrivenFilter

    快速过滤器

    元素是线驱动过滤器

    ElementIsElementTypeFilter

    快速过滤器

    指定元素类型进行驱动 

    ElementMulticategoryFilter 

    快速过滤器

    元素的多类别过滤 

    ElementMulticlassFilter

    快速过滤器

    元素的多类过滤 

    ElementOwnerViewFilter

    快速过滤器

    视图检索

    ElementStructuralTypeFilter 

    快速过滤器

    元素的结构类型 

    ElementWorksetFilter 

    快速过滤器

    指定工作集的元素过滤

    ExclusionFilter

    快速过滤器

    排除过滤器

    ExtensibleStorageFilter

    快速过滤器

    Schema类型的排除计算器

    FamilySymbolFilter

    快速过滤器

    族过滤器

      案例:

    案例1:查找包含指定点的墙体元素BoundingBoxContainsPointFilter

    BoundingBoxContainsPointFilter notContainFilter =
        new BoundingBoxContainsPointFilter(basePnt, true); 
    collector = new FilteredElementCollector(document);
    IList<Element> notContainFounds =
        collector.OfClass(typeof(Wall)).WherePasses(notContainFilter).ToElements();

    案例2:查找指定区域相交的元素对象BoundingBoxIntersectsFilter

    Outline myOutLn = new Outline(new XYZ(0, 0, 0), new XYZ(100, 100, 100));
    
    //创建轮廓
    BoundingBoxIntersectsFilter filter = new BoundingBoxIntersectsFilter(myOutLn);
    derived from ElementType
    FilteredElementCollector collector = new FilteredElementCollector(document);
    IList<Element> elements = collector.WherePasses(filter).ToElements();

    案例3:过滤查找指定区域内的元素

    Outline myOutLn = new Outline(new XYZ(0, 0, 0), new XYZ(100, 100, 100));
    
    //创建边界
    BoundingBoxIsInsideFilter filter = new BoundingBoxIsInsideFilter(myOutLn);
    
    derived from ElementType
    FilteredElementCollector collector = new FilteredElementCollector(document);
    IList<Element> elements = collector.WherePasses(filter).ToElements();

    案例4:通过元素的类别进行过滤指定元素

    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:
    ";
    foreach (Element e in walls)
    {
        prompt += e.Name + "
    ";
    }
    TaskDialog.Show("Revit", prompt);

    案例5:通过元素的类型进行过滤ElementClassFilter

    ElementClassFilter filter = new ElementClassFilter(typeof(FamilyInstance));
    
    
    FilteredElementCollector collector = new FilteredElementCollector(document);
    collector.WherePasses(filter);
    
    
    var query = from element in collector
                where element.Name == "60" x 30" Student"
                select element;
    List<FamilyInstance> familyInstances = query.Cast<FamilyInstance>().ToList<FamilyInstance>();

    案例6:

    2.2 ElementSlowFilter 慢过滤器常用在一个图形比较方面

    慢过滤器要求首先获得元素并在内存中展开。因此,最好将慢过滤器与至少一个ElementQuickFilter耦合,这应使扩展的元素数量最小化,以便根据该滤波器设置的标准进行评估。

    名称    

    类型

    作用

    备注

    RoomFilter

    慢过滤器

    查找房间

    RoomTagFilter

    慢过滤器

    查找房间标记

    AreaFilter

    慢过滤器

    查找区域

    AreaTagFilter

    慢过滤器

    查找区域标记

    CurveElementFilter

    慢过滤器

    指定元素类进行过滤

    ElementIntersectsFilter

    慢过滤器

    查找相关信息

    ElementLevelFilter

    慢过滤器

    查找标高信息

    ElementParameterFilter

    慢过滤器

    通过元素的参数

    ElementPhaseStatusFilter

    慢过滤器

    和指定阶段状态联系的元素

    FamilyInstanceFilter

    慢过滤器

    族实例查找

    SpaceFilter

    慢过滤器

    空间查找

    SpaceTagFilter

    慢过滤器

    空间标记查找

    PrimaryDesignOptionMemberFilter

    慢过滤器

    主选项所拥有的元素

    FamilyStructuralMaterialTypeFilter

    慢过滤器

    组的结构性材质过滤器

    StructuralInstanceUsageFilter

    慢过滤器

    结构实例

    StructuralMaterialTypeFilter

    慢过滤器

    结构性材质

    2.3 ElementLogicalFilter 逻辑过滤器,是实现过滤器的组合和复杂应用

    逻辑过滤器是实现组合和复杂过滤的过滤器。

    名称    

    类型

    作用

    备注

    LogicalAndFilter

    逻辑过滤器

    逻辑与

     

    LogicalOrFilter

    逻辑过滤器

    逻辑或

     

    主要解决过滤中的“或”与“与”的问题,and就是所有满足其中一个条件即可,OR就是要满足所有的条件。

  • 相关阅读:
    Rraspberry Pi 4B python3 安装opencv
    如何用arduion制作智能 垃圾桶
    MySQL(二)表结构的管理
    MySQL(一)基础操作
    vc++绘图基础
    网站签~
    (转)Oracle 知识日常积累
    利用反射判断bean属性不为空(null和空串)
    (转)Oracle 单字段拆分成多行
    svn 解决树冲突
  • 原文地址:https://www.cnblogs.com/minhost/p/14255775.html
Copyright © 2020-2023  润新知