Revit 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();

                    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);

                    //樓梯輪廓線/中心線
                    IList<Curve> bdryCurves = new List<Curve>();
                    IList<Curve> riserCurves = new List<Curve>();
                    IList<Curve> pathCurves = new List<Curve>();


                    //樓梯外輪廓線
                    bdryCurves.Add(Line.CreateBound(pnt1, pnt2));
                    bdryCurves.Add(Line.CreateBound(pnt3, pnt4));

                    // 步數及步線位置
                    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));
                    }

                    //樓梯中心線
                    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);

                    // 樓梯1
                    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;

                    // 樓梯2
                    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();
                }
                // 忽略創建的失敗事務【必須有】
                newStairsScope.Commit(new FailuresPreprocessor());
            }

            return newStairsId;
        }
 public class FailuresPreprocessor : IFailuresPreprocessor
    {
        public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
        {
            IList<FailureMessageAccessor> listFma = failuresAccessor.GetFailureMessages();
            if (listFma.Count == 0)
                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;
        }
    }

 

創建結果:

 

=========【更多高級應用請關注公衆號】========

 

===================================

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章