using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Architecture; namespace CreateStairs
{
[Transaction(TransactionMode.Manual)]
public class Class1:IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Document doc = commandData.Application.ActiveUIDocument.Document;
Transaction trans = new Transaction(doc,"new level");
trans.Start();
Level blvl = Level.Create(doc, );
Level tlvl = Level.Create(doc, );
trans.Commit();
CreateStairs(doc, blvl, tlvl);
return Result.Succeeded;
}
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(); // Create a sketched run for the stairs
IList<Curve> bdryCurves = new List<Curve>();
IList<Curve> riserCurves = new List<Curve>();
IList<Curve> pathCurves = new List<Curve>();
XYZ pnt1 = new XYZ(, , );
XYZ pnt2 = new XYZ(, , );
XYZ pnt3 = new XYZ(, , );
XYZ pnt4 = new XYZ(, , );
// boundaries
bdryCurves.Add(Line.CreateBound(pnt1, pnt2));
bdryCurves.Add(Line.CreateBound(pnt3, pnt4));
// riser curves
const int riserNum = ;
for (int ii = ; ii <= riserNum; ii++)
{
XYZ end0 = (pnt1 + pnt2) * ii / (double)riserNum;
XYZ end1 = (pnt3 + pnt4) * ii / (double)riserNum;
XYZ end2 = new XYZ(end1.X, , );
riserCurves.Add(Line.CreateBound(end0, end2));
} //stairs path curves
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);
// Add a straight run
Line locationLine = Line.CreateBound(new XYZ(, -, newRun1.TopElevation), new XYZ(, -, newRun1.TopElevation));
StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center);
newRun2.ActualRunWidth = ;
// Add a landing between the runs
CurveLoop landingLoop = new CurveLoop();
XYZ p1 = new XYZ(, , );
XYZ p2 = new XYZ(, , );
XYZ p3 = new XYZ(, -, );
XYZ p4 = new XYZ(, -, );
Line curve_1 = Line.CreateBound(p1, p2);
Line curve_2 = Line.CreateBound(p2, p3);
Line curve_3 = Line.CreateBound(p3, p4);
Line curve_4 = Line.CreateBound(p4, p1);
landingLoop.Append(curve_1);
landingLoop.Append(curve_2);
landingLoop.Append(curve_3);
landingLoop.Append(curve_4);
StairsLanding newLanding = StairsLanding.CreateSketchedLanding(document, newStairsId, landingLoop, newRun1.TopElevation);
stairsTrans.Commit();
}
// A failure preprocessor is to handle possible failures during the edit mode commitment process.
newStairsScope.Commit(new FailuresPreprocessor());//new StairsFailurePreprocessor());
}
return newStairsId;
} }
public class FailuresPreprocessor : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> listFma = failuresAccessor.GetFailureMessages();
if (listFma.Count == )
return FailureProcessingResult.Continue;
foreach (FailureMessageAccessor fma in listFma)
{
if (fma.GetSeverity() == FailureSeverity.Error)
{
if (fma.HasResolutions())
failuresAccessor.ResolveFailure(fma);
}
if (fma.GetSeverity() == FailureSeverity.Warning)
{
failuresAccessor.DeleteWarning(fma);
}
}
return FailureProcessingResult.ProceedWithCommit;
}
}
}

Revit api 创建楼梯图元的更多相关文章

  1. revit API 生成墙图元

    由于Revit的版本问题,在网上找的生成墙图元的代码,在我机器上的Revit 2016中编译不能通过,通过多次调试,终于找到在revit 2016中使用API生成墙图元的代码,现在贴出来. 下面的代码 ...

  2. Revit API创建标注NewTag

    start ;             )                 {                     eId = item;                 }            ...

  3. Revit api 创建族并加载到当前项目

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. Revit API创建墙的保温层修改墙厚度

    start [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)]  / ;         ; ...

  5. Revit API创建标高,单位转换

    一业内朋友让我写个快速创建标高的插件. ;             ; i <= iNum; i++)             {                 Level level = d ...

  6. Revit API创建一个拷贝房间内对象布局命令

    本课程演示创建一个拷贝房间内对象布局命令,完整演示步骤和代码.这个命令把选中房间内的对象复制到其它选中的一个或多个房间中,而且保持与源房间一致的相对位置.通过本讲座使听众知道创建一个二次开发程序很简单 ...

  7. Revit API创建几何实体Solid并找到与之相交的元素

    几何实体的创建方法之一:构成封闭底面,指定拉伸方向与拉伸高度.GeometryCreationUtilities ;         , pt.Y - dBoxLength / , pt.Z);    ...

  8. Revit API 创建带箭头的标注

      [Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class cmd : ...

  9. Revit API创建详图视图

    start //创建详图视图 Transaction ts = new Transaction(doc, "http://greatverve.cnblogs.com"); ts. ...

随机推荐

  1. java websocket学习

    引言: websocket,webservice傻傻分不清楚,都觉得是很高深的东西,理解中的webservice是一种协议,通信协议,类似http协议的那种,比如使用webservice协议调后台接口 ...

  2. jsch上传文件到服务器

    需求就是上传文件到服务器,服务器的存储地址由程序决定然后可以自动创建. 使用第三方:jsch JSch 是SSH2的一个纯Java实现.它允许你连接到一个sshd 服务器,使用端口转发,X11转发,文 ...

  3. Ubuntu 修改 /etc/resolv.conf 被清空 或重启不生效解决

    sudo gedit /etc/NetworkManager/NetworkManager.conf 注释掉 dns=dnsmasq [main] plugins=ifupdown,keyfile,o ...

  4. 卷积神经网络-Dropout

    dropout 是神经网络用来防止过拟合的一种方法,很简单,但是很实用. 基本思想是以一定概率放弃被激活的神经元,使得模型更健壮,相当于放弃一些特征,这使得模型不过分依赖于某些特征,即使这些特征是真实 ...

  5. Oracle 用户 表 表空间之间的关系和管理

    文献地址: https://blog.csdn.net/jmilk/article/details/51599260 https://www.cnblogs.com/roger112/p/768530 ...

  6. SpringMVC学习一

    先看SpringMVC的视图解析    以及 摘录自http://www.cnblogs.com/HigginCui/p/5856780.html的架构解析 1.DisPatcherServlet:前 ...

  7. <Using ZooKeeper><Deploy & Use>

    安装与部署 配置过程相当简单.集群模式部署: wget http://www-us.apache.org/dist/zookeeper/stable/zookeeper-3.4.10.tar.gz t ...

  8. ESP8266 问题

    根据SDK接口编写的程序在运行一段时间,大约15/18分钟左右,就会报错 [22:30:55.828] there is no poison after the block. Expected poi ...

  9. shell脚本实例-跟踪网站日常变动

    #!/usr/bin/bash #用途:跟踪网页是否有更新 if [ $# -ne 1 ];then echo -e "$Usage $0 URl " exit fi first_ ...

  10. JAVA将异常的堆栈信息转成String

    有时候我们需要将系统出现异常的堆栈信息显示到异常页面的一个隐藏的DIV内,这样查看源时就可以快速的定位到异常信息.这个时候就要将异常信息转成String. /* * 将异常的堆栈信息转成String ...