Revit API: Stairs 楼梯

前言

Revit 中似乎找不出比楼梯更加复杂的原生几何构件了,但在设计院,楼梯又都是给刚入门的小弟来画的,这个真是尴尬。

楼梯功能

Revit 楼梯功能更新了多少版已无从得知,好在现在只有一种类型的楼梯了。
由构件组成的楼梯,包括以下内容:

  • 梯段:直梯、螺旋梯段、U 形梯段、L 形梯段、自定义绘制的梯段
  • 平台:在梯段之间自动创建,通过拾取两个梯段,或通过创建自定义绘制的平台
  • 支撑(侧边和中心):随梯段自动创建,或通过拾取梯段或平台边缘创建
  • 栏杆扶手:在创建期间自动生成,或稍后放置
    在这里插入图片描述

楼梯 API

Stairs API 接口:

namespace Autodesk.Revit.DB.Architecture
{
    public class Stairs : Element
    {
        public ElementId MultistoryStairsId { get; }
        public int NumberOfStories { get; }
        public int ActualTreadsNumber { get; }
        public double Height { get; set; }
        public double TopElevation { get; }
        public double BaseElevation { get; }
        public int DesiredRisersNumber { get; set; }
        public int ActualRisersNumber { get; }
        public double ActualTreadDepth { get; set; }
        public double ActualRiserHeight { get; }
        public static bool IsByComponent(Document document, ElementId stairsId);
        public ICollection<ElementId> GetAssociatedRailings();
        public ICollection<ElementId> GetStairsLandings();
        public ICollection<ElementId> GetStairsRuns();
        public ICollection<ElementId> GetStairsSupports();
        public bool IsInEditMode();
    }
}

和楼梯本身相关的接口:
在这里插入图片描述
判断是否是组合楼梯,如果返回 False,即为其它类型楼梯,可能是多年前的楼梯版本:

public static bool IsByComponent(Document document, ElementId stairsId);

和多层楼梯相关接口:

public ElementId MultistoryStairsId { get; }
public int NumberOfStories { get; }

API 创建楼梯

创建步骤:

  1. 构造楼梯的边缘线、踏步线、路径,生成草图形式的梯段,StairsRun.CreateSketchedRun
  2. 给定路径和宽度,用 StairsRun.CreateStraightRun 生成直型梯段;
  3. 给定轮廓,用 StairsLanding.CreateSketchedLanding 生成平台;
    注意,以上步骤必须在 StairsEditScopeTransaction 中完成。

代码源自API文档。

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(0, 0, 0);
            XYZ pnt2 = new XYZ(15, 0, 0);
            XYZ pnt3 = new XYZ(0, 10, 0);
            XYZ pnt4 = new XYZ(15, 10, 0);

            // boundaries       
            bdryCurves.Add(Line.CreateBound(pnt1, pnt2));
            bdryCurves.Add(Line.CreateBound(pnt3, pnt4));

            // riser curves
            const int riserNum = 20;
            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));
            }

            //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(20, -5, newRun1.TopElevation), new XYZ(35, -5, newRun1.TopElevation));
            StairsRun newRun2 = StairsRun.CreateStraightRun(document, newStairsId, locationLine, StairsRunJustification.Center);
            newRun2.ActualRunWidth = 10;

            // Add a landing between the runs
            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);
            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 StairsFailurePreprocessor());
    }

    return newStairsId;
}

效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客BIM工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值