Revit API创建几何实体Solid并找到与之相交的元素
几何实体的创建方法之一:
构成封闭底面,指定拉伸方向与拉伸高度。GeometryCreationUtilities
//自创几何实体相交法 [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class FindIntersectWallsByGeometry : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { UIApplication app = commandData.Application; Document doc = app.ActiveUIDocument.Document; Transaction trans = new Transaction(doc, "ExComm"); trans.Start(); //pick a point to draw solid在屏幕上选择一点,找到附近的墙。 Selection sel = app.ActiveUIDocument.Selection; XYZ pt = sel.PickPoint("Please pick a point to get the close walls"); //XYZ pttemp1 = sel.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader end..."); //XYZ pttemp2 = sel.PickPoint(Autodesk.Revit.UI.Selection.ObjectSnapTypes.None, "Pick leader elbow..."); // double dBoxLength = 3; //Z值不变,以选择的点为中心,找到矩形四个点。 XYZ pt1 = new XYZ(pt.X - dBoxLength / 2, pt.Y - dBoxLength / 2, pt.Z); XYZ pt2 = new XYZ(pt.X + dBoxLength / 2, pt.Y - dBoxLength / 2, pt.Z); XYZ pt3 = new XYZ(pt.X + dBoxLength / 2, pt.Y + dBoxLength / 2, pt.Z); XYZ pt4 = new XYZ(pt.X - dBoxLength / 2, pt.Y + dBoxLength / 2, pt.Z); //创建四条线。 Line lineBottom = app.Application.Create.NewLineBound(pt1, pt2); Line lineRight = app.Application.Create.NewLineBound(pt2, pt3); Line lineTop = app.Application.Create.NewLineBound(pt3, pt4); Line lineLeft = app.Application.Create.NewLineBound(pt4, pt1); //封闭曲线 CurveLoop profile = new CurveLoop(); profile.Append(lineBottom); profile.Append(lineRight); profile.Append(lineTop); profile.Append(lineLeft); List<CurveLoop> loops = new List<CurveLoop>(); loops.Add(profile); //创建实体的方法(底面,拉伸方向,拉伸高度) XYZ vector = new XYZ(0, 0, 1); Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector, 10); //相交过滤器 FilteredElementCollector collector = new FilteredElementCollector(doc); ElementIntersectsSolidFilter solidFilter = new ElementIntersectsSolidFilter(solid); collector.WherePasses(solidFilter); sel.Elements.Clear(); //Add these interseting element to the selection foreach (Element elem in collector) { sel.Elements.Add(elem); } trans.Commit(); return Result.Succeeded; } }
转自博客Revit API创建几何实体Solid并找到与之相交的元素 - 大气象 - 博客园 (cnblogs.com)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构