revit api楼梯创建

news/2025/10/31 21:28:15/文章来源:https://www.cnblogs.com/miki969696/p/19181285

revit api楼梯创建

 

using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;namespace StairsCreation
{[Transaction(TransactionMode.Manual)]public class CreateStairsCommand : IExternalCommand{public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements){UIApplication uiApp = commandData.Application;UIDocument uiDoc = uiApp.ActiveUIDocument;Document doc = uiDoc.Document;try{// 获取或创建标高0和4000Level levelBottom = GetOrCreateLevel(doc, 0, "Level 0");Level levelTop = GetOrCreateLevel(doc, 4000, "Level 4000");if (levelBottom == null || levelTop == null){TaskDialog.Show("错误", "创建标高时发生错误。");return Result.Failed;}// 创建楼梯ElementId stairsId = CreateStairs(doc, levelBottom, levelTop);if (stairsId != null){TaskDialog.Show("成功", "楼梯已成功创建!");return Result.Succeeded;}else{TaskDialog.Show("失败", "创建楼梯时发生错误。");return Result.Failed;}}catch (Exception ex){message = ex.Message;return Result.Failed;}}private ElementId CreateStairs(Document document, Level levelBottom, Level levelTop){ElementId newStairsId = null;using (StairsEditScope newStairsScope = new StairsEditScope(document, "New Stairs")){newStairsId = newStairsScope.Start(levelBottom.Id, levelTop.Id);using (Transaction stairsTrans = new Transaction(document, "Add Runs and Landings to Stairs")){stairsTrans.Start();// 创建楼梯草图梯段IList<Curve> bdryCurves = new List<Curve>();IList<Curve> riserCurves = new List<Curve>();IList<Curve> pathCurves = new List<Curve>();XYZ pnt1 = new XYZ(0, 0, 0);XYZ pnt2 = new XYZ(15, 0, 0);XYZ pnt3 = new XYZ(0, 10, 0);XYZ pnt4 = new XYZ(15, 10, 0);// 边界曲线bdryCurves.Add(Line.CreateBound(pnt1, pnt2));bdryCurves.Add(Line.CreateBound(pnt3, pnt4));// 梯级曲线// 计算实际需要的踏步数量(考虑总高度4000)double totalHeight = levelTop.Elevation - levelBottom.Elevation;double riserHeight = 200; // 假设踏步高度为200int riserNum = (int)Math.Round(totalHeight / riserHeight);riserNum = Math.Max(1, riserNum); // 确保至少有一个踏步for (int ii = 0; ii <= riserNum; ii++){XYZ end0 = (pnt1 + pnt2) * ii / (double)riserNum;XYZ end1 = (pnt3 + pnt4) * ii / (double)riserNum;XYZ end2 = new XYZ(end1.X, 10, 0);riserCurves.Add(Line.CreateBound(end0, end2));}// 楼梯路径曲线XYZ pathEnd0 = (pnt1 + pnt3) / 2.0;XYZ pathEnd1 = (pnt2 + pnt4) / 2.0;pathCurves.Add(Line.CreateBound(pathEnd0, pathEnd1));StairsRun newRun1 = StairsRun.CreateSketchedRun(document, newStairsId,levelBottom.Elevation, bdryCurves, riserCurves, pathCurves);// 添加直梯段Line locationLine = Line.CreateBound(new XYZ(20, -5, newRun1.TopElevation),new XYZ(35, -5, newRun1.TopElevation));StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center);newRun2.ActualRunWidth = 10;// 在梯段之间添加平台CurveLoop landingLoop = new CurveLoop();XYZ p1 = new XYZ(15, 10, 0);XYZ p2 = new XYZ(20, 10, 0);XYZ p3 = new XYZ(20, -10, 0);XYZ p4 = new XYZ(15, -10, 0);landingLoop.Append(Line.CreateBound(p1, p2));landingLoop.Append(Line.CreateBound(p2, p3));landingLoop.Append(Line.CreateBound(p3, p4));landingLoop.Append(Line.CreateBound(p4, p1));StairsLanding newLanding = StairsLanding.CreateSketchedLanding(document, newStairsId, landingLoop, newRun1.TopElevation);stairsTrans.Commit();}// 提交楼梯编辑范围,处理可能的失败newStairsScope.Commit(new StairsFailurePreprocessor());}return newStairsId;}// 根据标高获取或创建Level元素private Level GetOrCreateLevel(Document doc, double elevation, string levelName){// 先尝试查找现有标高FilteredElementCollector collector = new FilteredElementCollector(doc);collector.OfClass(typeof(Level));foreach (Level level in collector){// 考虑浮点精度问题,使用容差比较if (Math.Abs(level.Elevation - elevation) < 0.001){return level;}}// 如果没有找到,创建新标高using (Transaction trans = new Transaction(doc, "Create Level")){trans.Start();Level newLevel = Level.Create(doc, elevation);newLevel.Name = levelName;trans.Commit();return newLevel;}}}// 楼梯创建失败处理器public class StairsFailurePreprocessor : IFailuresPreprocessor{public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor){IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();foreach (FailureMessageAccessor fma in failureMessages){// 接受所有警告if (fma.GetSeverity() == FailureSeverity.Warning){failuresAccessor.DeleteWarning(fma);}else // 对于错误,尝试修复或取消{return FailureProcessingResult.ProceedWithRollBack;}}return FailureProcessingResult.Continue;}}
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/952228.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

《代码大全2》初读有感

第一次翻开《代码大全2》的时候,我其实有点被它的厚度吓到了。这本厚得像砖头一样的书,真的能读完吗? 但慢慢读下去,我发现了很多有意思的地方。原来给变量取名有这么多讲究,以前我都是随便写个a、b、c的。作者说…

代码大全2{2}

最深的感悟是 “软件构建是系统性工程”。作者没有局限于代码本身,而是从软件质量目标、项目规划、团队协作等部分切入。其中关于 “技术债务” 的论述我觉得很有道理,每一次敷衍的设计都会为后续埋下隐患。优秀的程…

revit api 几何图元连接

revit api 几何图元连接namespace Autodesk.Revit.DB {public static class JoinGeometryUtils{public static bool AreElementsJoined(Document document, Element firstElement, Element secondElement);public sta…

读《代码大全2》读后感2

书中关于 “代码设计” 的内容,也帮我解决了大难题。在做图书管理系统时,我一股脑把所有功能都堆在一个类里,写了几百行代码后,想加个 “借阅记录查询” 功能,改一处就报错一处。直到看到书中说 “小型工具适合结…

公众号排版工具实测报告:为什么有一云AI编辑器成为全能高效的“排版专家”?

🧭 一、前言:AI排版正在重构创作效率 过去,公众号运营者最怕的不是写不出内容,而是排版。 错行、图片偏移、格式混乱…… 这些问题几乎每天都在消耗创作者的耐心。 但随着AI技术进入内容生态,“AI排版编辑器”迅…

代码大全2{1}

编程不只是写代码,前期的需求分析、架构设计和规划是高质量软件的基石。书强调 “磨刀不误砍柴工”,充分的前期准备能避免后期大量返工,那些关于项目复杂度评估、构建环境搭建的建议,既有理论高度又贴近实践,严谨…

Shooting Battle:Linux系统下的网络编程究极产物

服务器端 一、关键技术要点总结 1. 网络编程基础Socket API 使用:socket() → bind() → listen() → accept() 完整流程 TCP 字节流特性:无消息边界,需自定义协议(帧结束标记 <<<FRAME_END>>>)…

revit api隔离图元

revit api隔离图元namespace Autodesk.Revit.DB {public class View : Element{// 相关隔离的 APIpublic void ConvertTemporaryHideIsolateToPermanent();public void IsolateCategoriesTemporary(ICollection<Ele…

revit api明细表

revit api明细表如果想要读取明细表的内容,可以用 ViewSchedule 父类 TableView 的接口。 namespace Autodesk.Revit.DB {public class TableView : View{public int MaximumRowHeight { get; }public int MaximumCol…

【开题答辩实录分享】以《基于python的奶茶店分布数据分析与可视化》为例进行答辩实录分享 - 教程

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

2025.10.31

今天没课在宿舍躺一天

使用RNNoise进行音频降噪

使用RNNoise进行音频降噪操作系统:Debian 12.5_x64 & Windows10_x64 rnnoise版本:0.2 gcc版本:12.2.0 python版本: 3.9.13 RNNoise是一个将传统数字信号处理与深度学习相结合的开源实时音频降噪库,可在消耗极…

程序员修炼之道:从小工到专家读后感(2025_10_31)

在正确与容易之间:每个程序员都面临的永恒选择 《程序员修炼之道》的第七章像一面镜子,照出了每个程序员日常工作中最真实的挣扎。当“在正确与容易之间做选择”这个命题出现在面前时,我感到心头一震——这不正是我…

Python测试(下) _ 高效率把bug揪出来

Python测试(下) _ 高效率把bug揪出来#导入测试内置模块import unittest#导入要测试的api,Student为类名from _oop import Studentfrom _oop import SmallStudent#需要继承unittest.TestCase,def函数必须用test_开头…

如何精准驱动菜品识别模型--基于米尔瑞芯微RK3576边缘计算盒

在人工智能与边缘计算深度融合的今天,将AI模型高效部署于终端设备已成为产业智能化的关键。本文将分享基于米尔MYD-LR3576边缘计算盒子部署菜品识别安卓Demo的实战经验。该设备凭借其内置的强劲瑞芯微RK3576芯片,为视…

MPK(Mirage Persistent Kernel)源码笔记(4)--- 转译系统

MPK(Mirage Persistent Kernel)源码笔记(4)--- 转译系统 目录MPK(Mirage Persistent Kernel)源码笔记(4)--- 转译系统0x00 概要0x01 Task和Event1.1 可执行任务1.1.1 任务定义1.1.2 任务类型1.2 事件1.2.1 事件…

征程 6 | 多任务 不同帧率 部署方案

1.方案描述 推理多任务模型时,可能会有不同任务分支 部署不同帧率的需求,例如 BEV 动态任务 20 帧,静态任务 10 帧这种情况。最简单的方式是编译两个模型,分开推理:模型 1:backbone+neck+ 动态 head 模型 2:bac…

10月31号

今天进行了外语学习。

10月29号

今天进行了离散数学和马克思主义的学习

️ 深度解析我的 Overleaf 私有化部署:一份稳定、高兼容性的 `docker-compose.yaml`

通过私有化部署 Overleaf(ShareLaTeX CE),我们能彻底掌控一个功能完整的 LaTeX 协作环境,为您的论文编写和数据安全提供强大保障,告别官方服务的付费限制与硬件兼容性烦恼。大家好,我是 XuHe。在上一篇博客告别 …