Revit 二次开发 获得元素相交的其他元素

    根据自己的需求来使用 第二种有时会出现过滤不出来  

第一种方法 

思路是根据这个元素得到一个包围这个元素的盒子  和要过滤的相交元素的类别 组合成一个 筛选器

 /// <summary>
        /// 获取相交元素 boundingBox
        /// </summary>
        /// <param name="element">根据图元找相交</param>
        /// <param name="category">类别</param>
        /// <param name="contain">是否包含自身</param>
        /// <returns>查找结果</returns>
        public static List<Element> GetIntersectElements(this Element element, BuiltInCategory category,bool contain=false)
        {
            List<Element> listElement = new List<Element>();
            Document doc = element.Document;
            BoundingBoxXYZ boundingBoxXyz = element.get_BoundingBox(doc.ActiveView);
            Outline outline = new Outline(boundingBoxXyz.Min, boundingBoxXyz.Max);
            BoundingBoxIntersectsFilter boundFilter = new BoundingBoxIntersectsFilter(outline);
            ElementCategoryFilter filter2 = new ElementCategoryFilter(category);
            LogicalAndFilter filter3 = new LogicalAndFilter(boundFilter, filter2);
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            listElement = collector.WherePasses(filter3).WhereElementIsNotElementType().ToList();

            if (contain == false)
            {
               listElement.RemoveAll(m => m.Id == element.Id);
            }
           
            return listElement;
        }
        

 

第二种方法 

思路 先过滤类别 再根据api提供的相交的类进行过滤

        /// <summary>
        /// 获取相交图元
        /// </summary>
        /// <param name="element">根据图元找相交</param>
        /// <param name="category">类别</param>
        /// <param name="contain">是否包含自身</param>
        /// <returns>查找结果</returns>
        public static List<Element> GetIntersectElements(this Element element, BuiltInCategory category, bool contain = false)
        {
            var listResults = new FilteredElementCollector(element.Document).OfCategory(category).WherePasses(
                new ElementIntersectsElementFilter(element)).ToList();
                
            if (contain == false)
            {
                listResults.RemoveAll(p => p.Id == element.Id);
            }
            
            return listResults;
        }

  • 0
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值