public Result setup_stairs() { // https://help.autodesk.com/cloudhelp/2018/ENU/Revit-API/Revit_API_Developers_Guide/Revit_Geometric_Elements/Stairs_and_Railings/Creating_and_Editing_Stairs.html XYZ stairsline = new XYZ(146 / 12.0, 165 / 12.0, level.Elevation); ElementId newStairsId = null; using (StairsEditScope newStairsScope = new StairsEditScope(doc, "New Stairs")) { newStairsId = newStairsScope.Start(level.Id, level_above.Id); using (Transaction t = new Transaction(doc)) { t.Start("Create window"); Line locationLine = Line.CreateBound( stairsline, stairsline.Add(new XYZ(15, 0, 0))); StairsRun newRun2 = StairsRun.CreateStraightRun(doc, newStairsId, locationLine, StairsRunJustification.Center); // newRun2.ActualRunWidth = 10; t.Commit(); } newStairsScope.Commit(new MyRevit.StairsFailurePreprocessor()); } return(Result.Succeeded); }
/// <summary> /// This method creates the sketched run in Revit document. /// </summary> /// <param name="rvtDoc">Revit Document</param> /// <param name="winderRunId">Created winder run</param> private void CreateWinderRun(Document rvtDoc, ref ElementId winderRunId) { using (StairsEditScope stairsMode = new StairsEditScope(rvtDoc, GetType().Name)) { var winderOldRun = rvtDoc.GetElement(winderRunId) as StairsRun; var stairsId = ElementId.InvalidElementId; // Non-existed stairs, create a new one. if (winderOldRun == null) { // Find two levels to create a stairs between them FilteredElementCollector filterLevels = new FilteredElementCollector(rvtDoc); var levels = filterLevels.OfClass(typeof(Level)).ToElements(); List <Element> levelList = new List <Element>(); levelList.AddRange(levels); levelList.Sort((a, b) => { return(((Level)a).Elevation.CompareTo(((Level)b).Elevation)); }); // Start the stairs edit mode stairsId = stairsMode.Start(levelList[0].Id, levelList[1].Id); } else // using the existed stairs { // Start the stairs edit mode stairsId = stairsMode.Start(winderOldRun.GetStairs().Id); } using (Transaction winderTransaction = new Transaction(rvtDoc)) { // Start the winder creation transaction winderTransaction.Start(GetType().Name); // The boundaries is consist of internal and external boundaries. List <Curve> boundarys = new List <Curve>(); boundarys.AddRange(InnerBoundary); boundarys.AddRange(OuterBoundary); // Calculate the run elevation. Stairs stairs = rvtDoc.GetElement(stairsId) as Stairs; double elevation = ControlPoints[0].Z; double actualElevation = Math.Max(elevation, stairs.BaseElevation); // Create the run StairsRun run = StairsRun.CreateSketchedRun(rvtDoc, stairsId, actualElevation, boundarys, RiserLines, CenterWalkpath); if (ElementId.InvalidElementId != winderRunId) { // Delete the old run rvtDoc.Delete(winderRunId); } // output the new run winderRunId = run.Id; // Finish the winder run creation. winderTransaction.Commit(); } // Finish the stairs Edit mode. stairsMode.Commit(new StairsEditScopeFailuresPreprocessor()); } }
/// <summary> /// Execute the creation of the specified stairs assembly. /// </summary> public void GenerateStairs() { SetupLevels(); // Prepare and maintain StairsEditScope for stairs creation activities using (StairsEditScope editScope = new StairsEditScope(document, "Stairs Automation")) { // Instantiate the new stairs element. ElementId stairsElementId = editScope.Start(BottomLevel.Id, TopLevel.Id); // Remember the stairs for use in creation of the run and landing configurations. m_stairs = document.GetElement(stairsElementId) as Stairs; // Setup a transaction for use during the run and landing creation using (Transaction t = new Transaction(document, "Stairs Automation")) { t.Start(); // Setup the configuration IStairsConfiguration configuration = SetupHardcodedConfiguration(); if (configuration == null) { return; } // Create each run int numberOfRuns = configuration.GetNumberOfRuns(); for (int i = 0; i < numberOfRuns; i++) { configuration.CreateStairsRun(document, stairsElementId, i); } // Create each landing int numberOfLandings = configuration.GetNumberOfLandings(); for (int i = 0; i < numberOfLandings; i++) { configuration.CreateLanding(document, stairsElementId, i); } t.Commit(); } editScope.Commit( new StairsEditScopeFailuresPreprocessor()); } }