/// <summary> /// Create the winder stairs in the Document. /// </summary> /// <param name="rvtDoc">Revit Document.</param> private void GenerateWinderStairs(Document rvtDoc) { if (m_removeTheUpdater) { // unregister this updater UpdaterRegistry.UnregisterUpdater(m_updaterId, rvtDoc); return; } // Create the winder m_winder.ControlPoints = WinderUtil.CalculateControlPoints(rvtDoc, m_curveElements); m_winder.Build(rvtDoc, m_drawSketch, ref m_winderRunId); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { Document rvtDoc = commandData.Application.ActiveUIDocument.Document; var selectionIds = commandData.Application.ActiveUIDocument.Selection.GetElementIds(); if (selectionIds.Count != 2 && selectionIds.Count != 3) { message += "Please select two (or three) connected line elements. E.g. two (or three) connected straight Walls or Model Lines."; return(Result.Cancelled); } List <ElementId> selectedIds = new List <ElementId>(); selectedIds.AddRange(selectionIds); // Generate the winder creation parameters from selected elements. IList <XYZ> controlPoints = WinderUtil.CalculateControlPoints(rvtDoc, selectedIds); double runWidth = 0, treadDepth = 0; GetStairsData(rvtDoc, out runWidth, out treadDepth); IList <uint> maxCount = WinderUtil.CalculateMaxStepsCount(controlPoints, runWidth, treadDepth); uint numStepsInCorner = 3; double centerOffset = 0.0; if (selectionIds.Count == 2) { // Create L-Winder using (LWinderOptions options = new LWinderOptions()) { options.NumStepsAtStart = maxCount[0]; options.NumStepsAtEnd = maxCount[1]; options.NumStepsInCorner = numStepsInCorner; options.RunWidth = runWidth; options.CenterOffsetE = centerOffset; options.CenterOffsetF = centerOffset; if (options.ShowDialog() == DialogResult.OK) { LWinder lwinder = new LWinder(); lwinder.NumStepsAtStart = options.NumStepsAtStart; lwinder.NumStepsInCorner = options.NumStepsInCorner; lwinder.NumStepsAtEnd = options.NumStepsAtEnd; lwinder.RunWidth = options.RunWidth; lwinder.TreadDepth = treadDepth; lwinder.CenterOffsetE = options.CenterOffsetE; lwinder.CenterOffsetF = options.CenterOffsetF; AddInId activeid = options.DMU ? commandData.Application.ActiveAddInId : null; WinderUpdater lwinderDMU = new WinderUpdater(lwinder, selectedIds, rvtDoc, activeid, options.Sketch); } } } else if (selectionIds.Count == 3) { // Create U-Winder using (UWinderOptions options = new UWinderOptions()) { options.NumStepsAtStart = maxCount[0]; options.NumStepsInMiddle = maxCount[1]; options.NumStepsAtEnd = maxCount[2]; options.NumStepsInCorner1 = numStepsInCorner; options.NumStepsInCorner2 = numStepsInCorner; options.RunWidth = runWidth; options.CenterOffsetE1 = centerOffset; options.CenterOffsetF1 = centerOffset; options.CenterOffsetE2 = centerOffset; options.CenterOffsetF2 = centerOffset; if (options.ShowDialog() == DialogResult.OK) { UWinder uwinder = new UWinder(); uwinder.NumStepsAtStart = options.NumStepsAtStart; uwinder.NumStepsInCorner1 = options.NumStepsInCorner1; uwinder.NumStepsInMiddle = options.NumStepsInMiddle; uwinder.NumStepsInCorner2 = options.NumStepsInCorner2; uwinder.NumStepsAtEnd = options.NumStepsAtEnd; uwinder.RunWidth = options.RunWidth; uwinder.TreadDepth = treadDepth; uwinder.CenterOffsetE1 = options.CenterOffsetE1; uwinder.CenterOffsetF1 = options.CenterOffsetF1; uwinder.CenterOffsetE2 = options.CenterOffsetE2; uwinder.CenterOffsetF2 = options.CenterOffsetF2; AddInId activeid = options.DMU ? commandData.Application.ActiveAddInId : null; WinderUpdater uwinderDMU = new WinderUpdater(uwinder, selectedIds, rvtDoc, activeid, options.Sketch); } } } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }