Revit二次开发之按照标高过滤元素

Revit二次开发之按照标高过滤元素

之前群里有朋友问怎么过滤特定标高的元素,当时有人回答先都过滤出来,然后遍历判断相应的标高参数来找出特定标高的元素。今天在看书的时候看到了一个可以过滤特定标高元素的方法,在此记录一下。
这个demo实现了亮显标高 1中所有元素的效果。


using System;
using System.Collections.Generic;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.DB.Electrical;
using System.Threading;
using System.Linq;
using System.Runtime.InteropServices;

namespace 插件
{
    [Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Journaling(JournalingMode.UsingCommandData)]
    public class Command : IExternalCommand
    {
        public readonly double unit = 304.8;

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
        {
            UIApplication uiapp = new UIApplication(commandData.Application.Application);
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection selection = uidoc.Selection;

            Level level = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).OfClass(typeof(Level)).WhereElementIsNotElementType().ToElements().Where(m => m.Name == "标高 1").ToList().FirstOrDefault() as Level;
            // 创建一个标高过滤器
            ElementLevelFilter levelFilter = new ElementLevelFilter(level.Id);
            FilteredElementCollector coll = new FilteredElementCollector(doc);
            ICollection<ElementId> ids = coll.WhereElementIsNotElementType().WherePasses(levelFilter).ToElementIds();
            selection.SetElementIds(ids);
            return Result.Succeeded;
        }
    }
}
  • 参考——API开发指南 宦国胜 主编
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Revit二次开发中,过滤器是一种用于筛选Revit内部对象的工具。它们允许开发人员根据特定的条件来获取所需的元素。根据引用和引用,Revit提供了几种不同类型的过滤器,包括快速过滤器(ElementQuickFilter)、慢速过滤器(ElementSlowFilter)和逻辑过滤器(ElementLogicalFilter)。 快速过滤器(ElementQuickFilter)是一种低内存占用的过滤器类,它使用有限的接口来读取图元属性,被快速过滤器丢弃的图元不会展开到内存中。与快速过滤器相比,慢速过滤器(ElementSlowFilter)需要先获取并展开图元到内存中,因此使用慢速过滤器时,结合至少一个快速过滤器可以减少展开到内存中的图元数量。 逻辑过滤器(ElementLogicalFilter)可以组合两个或更多过滤器,Revit会根据过滤器的优先级重新排序以使过滤器执行最快。可以使用逻辑过滤器来实现复杂的过滤条件。 以下是一个使用过滤器的示例代码(引用): ```csharp //首先创建两个单独的过滤器 ElementClassFilter wallfilter = new ElementClassFilter(typeof(Wall)); ElementClassFilter floorfilter = new ElementClassFilter(typeof(Floor)); //然后用逻辑或过滤器将以上两个过滤器组合 var andfilter = new LogicalOrFilter(wallfilter, floorfilter); FilteredElementCollector collector = new FilteredElementCollector(doc); //应用过滤器 collector.WherePasses(filter); var wallandfloor = collector.ToList(); ``` 在这个示例中,我们首先创建了两个单独的过滤器,一个用于筛选墙(Wall),一个用于筛选楼板(Floor)。然后使用逻辑或过滤器将这两个过滤器组合起来,以获取既是墙又是楼板的元素。最后,我们使用过滤器应用到元素收集器上,并将筛选结果存储在wallandfloor变量中。 通过使用Revit过滤器,开发人员可以更灵活地获取和操作Revit模型中的元素,以满足特定的需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Revit二次开发](https://download.csdn.net/download/qq_20330893/9589049)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [revit二次开发——过滤器基础](https://blog.csdn.net/weixin_44037272/article/details/126408811)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [revit二次开发——过滤器2.筛选过滤器](https://blog.csdn.net/helloyangkl/article/details/127564928)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值