revit 碰撞检测相关
Revit二次开发:由房间获取房间的墙
之前用的方法是由房间边界构成的Solid,计算与该Solid相交的Element,然后判断是否为墙。相对来说这个方法比较通用,可以检索出房间的楼板、窗户等各种构件。
SpatialElementBoundaryOptions se=new SpatialElementBoundaryOptions();
se.SpatialElementBoundaryLocation = SpatialElementBoundaryLocation.Center;
SpatialElementGeometryCalculator calculator =new SpatialElementGeometryCalculator(document,se);
Solid solid = calculator.CalculateSpatialElementGeometry(room)?.GetGeometry();
var list = new FilteredElementCollector(document).WhereElementIsNotElementType().
WherePasses(new ElementIntersectsSolidFilter(solid)).ToList();
foreach (var element in list)
{
Wall wall=element as Wall;
if (wall!=null)
{
wallsOfRoom.Add(wall);
}
}
只是找墙的话,其实用BoundarySegment.ElementId,就可以直接得到构成这个边界部分的元素(墙)。
IList<IList<BoundarySegment>> loops = room.GetBoundarySegments(new SpatialElementBoundaryOptions());
foreach (IList<BoundarySegment> loop in loops)
{
foreach (BoundarySegment segment in loop)
{
Wall wall =document.GetElement(segment.ElementId) as Wall;
if (wall != null)
{
wallsOfRoom.Add(wall);
}
}
}
-
碰撞检测:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;//类Selection使用
namespace Collision
{
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
Transaction trans = new Transaction(doc,"Excomm");
trans.Start();
Selection select = uiDoc.Selection;
Reference r = select.PickObject(ObjectType.Element, "选择需要检查的墙");
Element column = doc.GetElement(r);
FilteredElementCollector collect = new FilteredElementCollector(doc);
//ElementIntersectionFilter冲突检查
ElementIntersectsElementFilter iFilter = new ElementIntersectsElementFilter(column,false);
collect.WherePasses(iFilter);
List<ElementId> excludes = new List<ElementId>();
excludes.Add(column.Id);
collect.Excluding(excludes);
List<ElementId> ids = new List<ElementId>();
select.SetElementIds(ids);
foreach(Element elem in collect)//遍历每一个元素
{
ids.Add(elem.Id);//将elem的Id添加到List中
}
select.SetElementIds(ids);
trans.Commit();
return Result.Succeeded;
}
}
}筛选出和该元素相交的元素之BoundingBoxIntersectsFilter
//假设元素为ee
BoundingBoxXYZ box = ee.get_BoundingBox(doc.ActiveView);
//创建outline,通过boundingboxintersect过滤器
Outline myOutLn = new Outline(box.Min, box.Max);
BoundingBoxIntersectsFilter boxee = new BoundingBoxIntersectsFilter(myOutLn);
FilteredElementCollector collector = new FilteredElementCollector(doc);//过滤出相交元素,假设用到的是板类型
IList<Element> elements = collector.OfClass(typeof(Floor)).WherePasses(boxee).ToElements();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架