added Revit 2022 SDK minus except *rvt and *rfa

This commit is contained in:
Jeremy Tammik
2021-04-20 11:36:21 +02:00
parent 1133a82dc5
commit 7e327986e8
3034 changed files with 1245318 additions and 0 deletions
@@ -0,0 +1,72 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Generic;
using Autodesk.Revit;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// Implements the Revit add-in interface IExternalCommand
/// </summary>
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
public class Command : IExternalCommand
{
#region IExternalCommand Members
/// <summary>
/// The implementation of the automatic stairs creation command.
/// </summary>
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
UIDocument activeDocument = commandData.Application.ActiveUIDocument;
Document document = activeDocument.Document;
// Create an automation utility with a hardcoded stairs configuration number
StairsAutomationUtility utility = StairsAutomationUtility.Create(document, stairsConfigs[stairsIndex]);
// Generate the stairs
utility.GenerateStairs();
stairsIndex++;
if (stairsIndex > 4)
stairsIndex = 0;
return Result.Succeeded;
}
#endregion
private static int stairsIndex = 0;
private static int[] stairsConfigs = { 0, 3, 4, 1, 2 };
}
}
@@ -0,0 +1,64 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// Description of GeometryUtils.
/// </summary>
public static class GeometryUtils
{
/// <summary>
/// Creates a duplicate of a set of curves, applying the specified transform to each.
/// </summary>
/// <param name="inputs">The inputs.</param>
/// <param name="trf">The transformation.</param>
/// <returns>The copy of the curves.</returns>
public static IList<Curve> TransformCurves(IList<Curve> inputs, Transform trf)
{
int numCurves = inputs.Count;
List<Curve> result = new List<Curve>(numCurves);
for (int i = 0; i < numCurves; i++)
{
result.Add(TransformCurve(inputs[i], trf));
}
return result;
}
/// <summary>
/// Creates a duplicate curve, applying the specified transform to each.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="trf">The transformation.</param>
/// <returns>The copy of the curve.</returns>
public static Curve TransformCurve(Curve input, Transform trf)
{
Curve trfCurve = input.CreateTransformed(trf);
return trfCurve;
}
}
}
@@ -0,0 +1,70 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// This interface represents a configuration of stairs runs and landings to be created.
/// </summary>
public interface IStairsConfiguration
{
/// <summary>
/// Returns the number of stairs runs in the stairs assembly.
/// </summary>
/// <returns>The number of runs.</returns>
int GetNumberOfRuns();
/// <summary>
/// Creates the stairs run with the given index.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="stairsElementId">The id of the stairs element.</param>
/// <param name="runIndex">The run index.</param>
void CreateStairsRun(Document document, ElementId stairsElementId, int runIndex);
/// <summary>
/// Returns the number of landings in the stairs assembly.
/// </summary>
/// <returns>The number of landings.</returns>
int GetNumberOfLandings();
/// <summary>
/// Creates the stairs landing with the given index.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="stairsElementId">The id of the stairs element.</param>
/// <param name="landingIndex">The landing index.</param>
void CreateLanding(Document document, ElementId stairsElementId, int landingIndex);
/// <summary>
/// Assigns the width of the stairs runs.
/// </summary>
/// <param name="width">The width.</param>
void SetRunWidth(double width);
}
}
@@ -0,0 +1,57 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// An interface that represents a landing.
/// </summary>
public interface IStairsLandingComponent
{
/// <summary>
/// Obtains the curves that bound the landing.
/// </summary>
/// <returns>The boundary curves.</returns>
CurveLoop GetLandingBoundary();
/// <summary>
/// Obtains the elevation of the landing.
/// </summary>
/// <returns>The elevation.</returns>
double GetLandingBaseElevation();
/// <summary>
/// Creates the landing component represented by this configuration.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="stairsElementId">The stairs element id.</param>
/// <returns>The new landing.</returns>
StairsLanding CreateLanding(Document document, ElementId stairsElementId);
}
}
@@ -0,0 +1,107 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// Utilities used in processing of landings.
/// </summary>
public class LandingComponentUtils
{
/// <summary>
/// Returns a new set of curves created as a projection of the input curves to the provided elevation.
/// </summary>
/// <remarks>Assumes, but does not validate, that the curves are in the XY plane.</remarks>
/// <param name="curves">The curves.</param>
/// <param name="elevation">The target elevation.</param>
/// <returns>The projected curves.</returns>
public static IList<Curve> ProjectCurvesToElevation(IList<Curve> curves, double elevation)
{
List<Curve> ret = new List<Curve>();
foreach (Curve curve in curves)
{
ret.Add(ProjectCurveToElevation(curve, elevation));
}
return ret;
}
/// <summary>
/// Returns a new curve created as a projection of the input curve to the provided elevation.
/// </summary>
/// <remarks>Assumes, but does not validate, that the curve is in the XY plane.</remarks>
/// <param name="curve">The curve.</param>
/// <param name="elevation">The target elevation.</param>
/// <returns>The projected curve.</returns>
public static Curve ProjectCurveToElevation(Curve curve, double elevation)
{
double offset1 = elevation - curve.GetEndPoint(0).Z;
Curve projectedCurve = curve.CreateTransformed(Transform.CreateTranslation(new XYZ(0, 0, offset1)));
return projectedCurve;
}
/// <summary>
/// Given two linear inputs, finds the combination of endpoints from each line which are farthest from each other, and returns a line
/// connecting those points.
/// </summary>
/// <param name="line1">The first line.</param>
/// <param name="line2">The second line.</param>
/// <returns>The longest line connecting one endpoint from each line. </returns>
public static Line FindLongestEndpointConnection(Line line1, Line line2)
{
double maxDistance = 0.0;
XYZ endPoint1 = null;
XYZ endPoint2 = null;
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
double distance = line1.GetEndPoint(j).DistanceTo(line2.GetEndPoint(i));
if (distance > maxDistance)
{
maxDistance = distance;
endPoint1 = line1.GetEndPoint(j);
endPoint2 = line2.GetEndPoint(i);
}
}
}
return Line.CreateBound(endPoint1, endPoint2);
}
/// <summary>
/// Computes the parameter of the point projected onto the curve.
/// </summary>
/// <param name="curve">The curve.</param>
/// <param name="point">The point.</param>
/// <returns>The parameter of the projected point.</returns>
public static double ComputeParameter(Curve curve, XYZ point)
{
IntersectionResult result = curve.Project(point);
return result.Parameter;
}
}
}
@@ -0,0 +1,99 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A configuration for creation of a landing with a fixed cross section.
/// </summary>
public class StairsRectangleLandingComponent : IStairsLandingComponent
{
/// <summary>
/// Creates a new StairsRectangleLandingConfiguration.
/// </summary>
/// <param name="stairsRunBoundary1">The end curve of the lower stair run.</param>
/// <param name="stairsRunBoundary2">The start curve of the higher stair run.</param>
/// <param name="runDirection">A vector representing the direction of the lower stair run.</param>
/// <param name="elevation">The elevation of the landing.</param>
/// <param name="width">The width of the landing.</param>
public StairsRectangleLandingComponent(Line stairsRunBoundary1, Line stairsRunBoundary2, XYZ runDirection, double elevation, double width)
{
// offset to base elevation
m_stairsRunBoundary1 = LandingComponentUtils.ProjectCurveToElevation(stairsRunBoundary1, elevation) as Line;
m_stairsRunBoundary2 = LandingComponentUtils.ProjectCurveToElevation(stairsRunBoundary2, elevation) as Line;
m_runDirection = runDirection;
m_width = width;
m_elevation = elevation;
}
private Line m_stairsRunBoundary1;
private Line m_stairsRunBoundary2;
private XYZ m_runDirection;
private double m_width;
private double m_elevation;
#region IStairsLandingConfiguration Members
/// <summary>
/// Implements the interface method.
/// </summary>
public Autodesk.Revit.DB.CurveLoop GetLandingBoundary()
{
// TODO : What if not collinear
Line boundaryLine = LandingComponentUtils.FindLongestEndpointConnection(m_stairsRunBoundary1, m_stairsRunBoundary2);
// offset by 1/2 of width
Curve centerCurve = boundaryLine.CreateTransformed(Transform.CreateTranslation(m_runDirection * (m_width / 2.0)));
// Create by Thicken
CurveLoop curveLoop = CurveLoop.CreateViaThicken(centerCurve, m_width, XYZ.BasisZ);
return curveLoop;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public double GetLandingBaseElevation()
{
return m_elevation;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public StairsLanding CreateLanding(Document document, ElementId stairsElementId)
{
return StairsLanding.CreateSketchedLanding(document, stairsElementId, GetLandingBoundary(), GetLandingBaseElevation());
}
#endregion
}
}
@@ -0,0 +1,55 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("StairsAutomationSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Autodesk, Inc. 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("cdde02c2-92b0-48e5-a239-bfd217307226")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,243 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs component consisting of a single curved run.
/// </summary>
class CurvedStairsRunComponent : TransformedStairsComponent, IStairsRunComponent
{
/// <summary>
/// Creates a new CurvedStairsRunConfiguration at the default location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers in the run.</param>
/// <param name="bottomElevation">The bottom elevation.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width.</param>
/// <param name="innerRadius">The radius of the innermost edge of the run.</param>
/// <param name="appCreate">The Revit API application creation object.</param>
public CurvedStairsRunComponent(int riserNumber, double bottomElevation,
double desiredTreadDepth, double width,
double innerRadius, Autodesk.Revit.Creation.Application appCreate) :
base()
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_innerRadius = innerRadius;
m_outerRadius = innerRadius + width;
m_incrementAngle = desiredTreadDepth / (m_innerRadius + width / 2.0);
m_desiredTreadDepth = desiredTreadDepth;
m_includedAngle = m_incrementAngle * (riserNumber - 1);
m_center = new XYZ(0, 0, bottomElevation);
m_appCreate = appCreate;
}
/// <summary>
/// Creates a new CurvedStairsRunConfiguration at the specified location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers in the run.</param>
/// <param name="bottomElevation">The bottom elevation.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width.</param>
/// <param name="innerRadius">The radius of the innermost edge of the run.</param>
/// <param name="appCreate">The Revit API application creation object.</param>
/// <param name="transform">The transformation (location and orientation).</param>
public CurvedStairsRunComponent(int riserNumber, double bottomElevation,
double desiredTreadDepth, double width,
double innerRadius, Autodesk.Revit.Creation.Application appCreate,
Transform transform) :
base(transform)
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_innerRadius = innerRadius;
m_outerRadius = innerRadius + width;
m_incrementAngle = desiredTreadDepth / (m_innerRadius + width / 2.0);
m_includedAngle = m_incrementAngle * (riserNumber - 1);
m_desiredTreadDepth = desiredTreadDepth;
m_center = new XYZ(0, 0, bottomElevation);
m_appCreate = appCreate;
}
private int m_riserNumber;
private double m_bottomElevation;
private double m_innerRadius;
private double m_outerRadius;
private double m_incrementAngle;
private double m_includedAngle;
private double m_desiredTreadDepth;
private XYZ m_center;
private Autodesk.Revit.Creation.Application m_appCreate;
private StairsRun m_stairsRun;
#region IStairsRunConfiguration members
/// <summary>
/// Implements the interface property.
/// </summary>
public double RunElevation
{
get
{
return m_bottomElevation;
}
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double TopElevation
{
get
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
return m_stairsRun.TopElevation;
}
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Curve> GetStairsPath()
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
CurveLoop curveLoop = m_stairsRun.GetStairsPath();
return curveLoop.ToList();
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetFirstCurve()
{
return GetEndCurve(false);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetLastCurve()
{
return GetEndCurve(true);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public XYZ GetRunEndpoint()
{
return GetLastCurve().GetEndPoint(0);
}
/// <summary>
/// Implements the interface property.
/// </summary>
private double Radius
{
get
{
return (m_innerRadius + m_outerRadius) / 2.0;
}
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Autodesk.Revit.DB.Architecture.StairsRun CreateStairsRun(Document document, ElementId stairsId)
{
m_stairsRun = StairsRun.CreateSpiralRun(document, stairsId, TransformPoint(m_center),
Radius, 0, m_includedAngle, true, StairsRunJustification.Center);
Width = m_outerRadius - m_innerRadius;
document.Regenerate(); // to get updated width
return m_stairsRun;
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double Width
{
get
{
return m_outerRadius - m_innerRadius;
}
set
{
m_outerRadius = value + m_innerRadius;
if (m_stairsRun != null)
{
m_stairsRun.ActualRunWidth = m_outerRadius - m_innerRadius;
m_incrementAngle = m_desiredTreadDepth / (m_innerRadius + value / 2.0);
}
}
}
#endregion
/// <summary>
/// Gets the first or last riser curve of the run.
/// </summary>
/// <param name="last">True to get the last curve, false to get the first.</param>
/// <returns>The curve.</returns>
private Curve GetEndCurve(bool last)
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
// Obtain the footprint boundary
CurveLoop boundary = m_stairsRun.GetFootprintBoundary();
// Obtain the endpoint of the stairs path matching the desired end,
// and find out which curve contains this point.
CurveLoop path = m_stairsRun.GetStairsPath();
Curve pathCurve = path.First<Curve>();
XYZ pathPoint = pathCurve.GetEndPoint(last ? 1 : 0);
foreach (Curve boundaryCurve in boundary)
{
if (boundaryCurve.Project(pathPoint).XYZPoint.IsAlmostEqualTo(pathPoint))
{
return boundaryCurve;
}
}
throw new Exception("Unable to find an intersecting boundary curve in the run.");
}
}
}
@@ -0,0 +1,103 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// The base interface for a single stairs run.
/// </summary>
public interface IStairsRunComponent
{
/// <summary>
/// Causes the run to be created.
/// </summary>
/// <remarks>The stairs must be properly set in the stairs edit mode, with an open transaction.</remarks>
/// <param name="document">The document.</param>
/// <param name="stairsId">The stairs id.</param>
/// <returns>The new stairs run.</returns>
StairsRun CreateStairsRun(Document document, ElementId stairsId);
/// <summary>
/// The bottom elevation of the run.
/// </summary>
double RunElevation
{
get;
}
/// <summary>
/// The top elevation of the run.
/// </summary>
/// <throws cref="NotSupportedException">Thrown if the stairs run has not been created, and this cannot be calculated without it.</throws>
double TopElevation
{
get;
}
/// <summary>
/// The width of the run.
/// </summary>
double Width
{
get;
set;
}
/// <summary>
/// Gets the path of the stairs run.
/// </summary>
/// <remarks>This is not guaranteed to succeed if the run has not been created.</remarks>
/// <returns>The stairs path.</returns>
/// <throws cref="NotSupportedException">Thrown if the stairs run has not been created, and this cannot be calculated without it.</throws>
IList<Curve> GetStairsPath();
/// <summary>
/// Gets the first tread line for the run.
/// </summary>
/// <remarks>This is not guaranteed to succeed if the run has not been created.</remarks>
/// <returns>The first curve.</returns>
/// <throws cref="NotSupportedException">Thrown if the stairs run has not been created, and this cannot be calculated without it.</throws>
Curve GetFirstCurve();
/// <summary>
/// Gets the last tread line for the run.
/// </summary>
/// <remarks>This is not guaranteed to succeed if the run has not been created.</remarks>
/// <returns>The last curve.</returns>
/// <throws cref="NotSupportedException">Thrown if the stairs run has not been created, and this cannot be calculated without it.</throws>
Curve GetLastCurve();
/// <summary>
/// Gets the endpoint of the run for purposes of locating the next run.
/// </summary>
/// <remarks>If the run "start point" is the lower left corner of the two dimensional projection of the run, this is the "upper right".
/// This is not guaranteed to succeed if the run has not been created.</remarks>
/// <returns>The endpoint.</returns>
/// <throws cref="NotSupportedException">Thrown if the stairs run has not been created, and this cannot be calculated without it.</throws>
XYZ GetRunEndpoint();
}
}
@@ -0,0 +1,252 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs run consisting of a single sketched curved run.
/// </summary>
/// <remarks>Because this is sketched, the maximum covered angle for the stair is 360 degrees.</remarks>
class SketchedCurvedStairsRunComponent : TransformedStairsComponent, IStairsRunComponent
{
/// <summary>
/// Creates a new SketchedCurvedStairsRunConfiguration at the default location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers in the run.</param>
/// <param name="bottomElevation">The bottom elevation.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width.</param>
/// <param name="innerRadius">The radius of the innermost edge of the run.</param>
/// <param name="appCreate">The Revit API application creation object.</param>
public SketchedCurvedStairsRunComponent(int riserNumber, double bottomElevation,
double desiredTreadDepth, double width,
double innerRadius, Autodesk.Revit.Creation.Application appCreate) :
base()
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_innerRadius = innerRadius;
m_outerRadius = innerRadius + width;
m_incrementAngle = desiredTreadDepth / (m_innerRadius + width / 2.0);
m_includedAngle = m_incrementAngle * (riserNumber - 1);
if (m_includedAngle > 2 * Math.PI)
throw new Exception("Arguments provided require an included angle of more than 360 degrees");
m_center = new XYZ(0, 0, bottomElevation);
m_appCreate = appCreate;
}
/// <summary>
/// Creates a new SketchedCurvedStairsRunConfiguration at the specified location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers in the run.</param>
/// <param name="bottomElevation">The bottom elevation.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width.</param>
/// <param name="innerRadius">The radius of the innermost edge of the run.</param>
/// <param name="appCreate">The Revit API application creation object.</param>
/// <param name="transform">The transformation (location and orientation).</param>
public SketchedCurvedStairsRunComponent(int riserNumber, double bottomElevation,
double desiredTreadDepth, double width,
double innerRadius, Autodesk.Revit.Creation.Application appCreate,
Transform transform) :
base(transform)
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_innerRadius = innerRadius;
m_outerRadius = innerRadius + width;
m_incrementAngle = desiredTreadDepth / (m_innerRadius + width / 2.0);
m_includedAngle = m_incrementAngle * (riserNumber - 1);
if (m_includedAngle > 2 * Math.PI)
throw new Exception("Arguments provided require an included angle of more than 360 degrees");
m_center = new XYZ(0, 0, bottomElevation);
m_appCreate = appCreate;
}
private int m_riserNumber;
private double m_bottomElevation;
private double m_innerRadius;
private double m_outerRadius;
private double m_incrementAngle;
private double m_includedAngle;
private XYZ m_center;
private Autodesk.Revit.Creation.Application m_appCreate;
private StairsRun m_stairsRun;
#region IStairsConfiguration members
/// <summary>
/// Implements the interface property.
/// </summary>
public double RunElevation
{
get
{
return m_bottomElevation;
}
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double TopElevation
{
get
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
return m_stairsRun.TopElevation;
}
}
/// <summary>
/// Implements the interface method.
/// </summary>
public double GetRunElevation()
{
return m_bottomElevation;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Autodesk.Revit.DB.Curve> GetStairsPath()
{
List<Curve> ret = new List<Curve>();
Arc arc = Arc.Create(m_center, (m_innerRadius + m_outerRadius) / 2.0, 0, m_includedAngle, XYZ.BasisX, XYZ.BasisY);
ret.Add(arc);
return ret;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetFirstCurve()
{
return GetRunRiserCurves().First<Curve>();
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetLastCurve()
{
return GetRunRiserCurves().Last<Curve>();
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Autodesk.Revit.DB.Curve> GetRunRiserCurves()
{
double incAngle = 0.0;
XYZ center = XYZ.Zero;
List<Curve> ret = new List<Curve>();
// Run riser curves are linear and radial with respect to the center of curvature.
for (int i = 0; i < m_riserNumber - 1; i++)
{
XYZ start = center + new XYZ(m_innerRadius * Math.Cos(incAngle), m_innerRadius * Math.Sin(incAngle), 0);
XYZ end = center + new XYZ(m_outerRadius * Math.Cos(incAngle), m_outerRadius * Math.Sin(incAngle), 0);
ret.Add(Line.CreateBound(start, end));
incAngle += m_incrementAngle;
}
// last one handled manually to ensure that it intersects end curves
IList<Curve> boundaryCurves = GetRunBoundaryCurves();
ret.Add(Line.CreateBound(boundaryCurves[0].Evaluate(1.0, true), boundaryCurves[1].Evaluate(1.0, true)));
return ret;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public XYZ GetRunEndpoint()
{
return GetRunBoundaryCurves()[1].GetEndPoint(1);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Autodesk.Revit.DB.Curve> GetRunBoundaryCurves()
{
List<Curve> ret = new List<Curve>();
Arc arc = Arc.Create(m_center, m_innerRadius, 0, m_includedAngle, XYZ.BasisX, XYZ.BasisY);
ret.Add(arc);
arc = Arc.Create(m_center, m_outerRadius, 0, m_includedAngle, XYZ.BasisX, XYZ.BasisY);
ret.Add(arc);
return ret;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Autodesk.Revit.DB.Architecture.StairsRun CreateStairsRun(Document document, ElementId stairsId)
{
m_stairsRun = StairsRun.CreateSketchedRun(document, stairsId, GetRunElevation(),
Transform(GetRunBoundaryCurves()), Transform(GetRunRiserCurves()),
Transform(GetStairsPath()));
document.Regenerate();
return m_stairsRun;
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double Width
{
get
{
return m_outerRadius - m_innerRadius;
}
set
{
if (m_stairsRun != null)
{
throw new InvalidOperationException("Cannot change width of already existing sketched run.");
}
m_outerRadius = value + m_innerRadius;
}
}
#endregion
}
}
@@ -0,0 +1,250 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs run consisting of a single sketched straight run.
/// </summary>
public class SketchedStraightStairsRunComponent : TransformedStairsComponent, IStairsRunComponent
{
/// <summary>
/// Creates a new sketched run configuration at the default location and orientation.
/// </summary>
/// <remarks>Stairs run boundary curves can be calculated before the run is created.</remarks>
/// <param name="riserNumber">The number of risers.</param>
/// <param name="bottomElevation">The bottom elevation.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width of the run.</param>
public SketchedStraightStairsRunComponent(int riserNumber, double bottomElevation, double desiredTreadDepth, double width):
base()
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_desiredTreadDepth = desiredTreadDepth;
m_width = width;
m_runExtent = new XYZ(0, (riserNumber - 1) * desiredTreadDepth, 0);
m_widthOffset = new XYZ(m_width, 0, 0);
}
/// <summary>
/// Creates a new sketched run configuration at the specified location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers.</param>
/// <param name="bottomElevation">The bottom elevation.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width of the run.</param>
/// <param name="transform">The transform (location and orientation).</param>
public SketchedStraightStairsRunComponent(int riserNumber, double bottomElevation, double desiredTreadDepth, double width, Transform transform):
base(transform)
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_desiredTreadDepth = desiredTreadDepth;
m_width = width;
// This is the full extent of the run across all treads
m_runExtent = new XYZ(0, (riserNumber - 1) * desiredTreadDepth, 0);
m_widthOffset = new XYZ(m_width, 0, 0);
}
private int m_riserNumber;
private double m_bottomElevation;
private double m_desiredTreadDepth;
private double m_width;
private XYZ m_runExtent;
private XYZ m_widthOffset;
private StairsRun m_stairsRun;
#region IStairsRunConfiguration members
/// <summary>
/// Implements the interface property.
/// </summary>
public double RunElevation
{
get
{
return m_bottomElevation;
}
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double TopElevation
{
get
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
return m_stairsRun.TopElevation;
}
}
/// <summary>
/// Implements the interface method.
/// </summary>
public double GetRunElevation()
{
return m_bottomElevation;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Autodesk.Revit.DB.Curve> GetStairsPath()
{
// Proceed up the middle of the run to the run extent
XYZ start = new XYZ(m_width / 2.0, 0, m_bottomElevation);
XYZ end = start + m_runExtent;
Line curve1 = Line.CreateBound(start, end);
List<Curve> ret = new List<Curve>();
ret.Add(curve1);
return Transform(ret);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetFirstCurve()
{
return GenerateRunRiserCurves().First<Curve>();
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetLastCurve()
{
return GenerateRunRiserCurves().Last<Curve>();
}
/// <summary>
/// Implements the interface method.
/// </summary>
public XYZ GetRunEndpoint()
{
return GetLastCurve().GetEndPoint(1);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Autodesk.Revit.DB.Curve> GetRunBoundaryCurves()
{
return Transform(GenerateUntransformedRunBoundaryCurves());
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Autodesk.Revit.DB.Architecture.StairsRun CreateStairsRun(Document document, ElementId stairsId)
{
m_stairsRun = StairsRun.CreateSketchedRun(document, stairsId, GetRunElevation(),
GetRunBoundaryCurves(), GenerateRunRiserCurves(),
GetStairsPath());
document.Regenerate();
return m_stairsRun;
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double Width
{
get
{
return m_width;
}
set
{
if (m_stairsRun != null)
{
throw new InvalidOperationException("Cannot change width of sketched run.");
}
m_width = value;
}
}
#endregion
/// <summary>
/// Generates the run boundary curves (not transformed by the stored transformation).
/// </summary>
/// <returns></returns>
private IList<Autodesk.Revit.DB.Curve> GenerateUntransformedRunBoundaryCurves()
{
// Start at 0, 0 and extend to the run extent
XYZ start = new XYZ(0, 0, m_bottomElevation);
XYZ end = start + m_runExtent;
Line curve1 = Line.CreateBound(start, end);
List<Curve> ret = new List<Curve>();
ret.Add(curve1);
// Start offset along the width and extend to the run extent
start = new XYZ(m_width, 0, m_bottomElevation);
end = start + m_runExtent;
Line curve2 = Line.CreateBound(start, end);
ret.Add(curve2);
return ret;
}
/// <summary>
/// Generates the riser curves for the sketch.
/// </summary>
/// <returns></returns>
private IList<Autodesk.Revit.DB.Curve> GenerateRunRiserCurves()
{
List<Curve> ret = new List<Curve>();
// Generate all curves but the last by incrementing along the tread depth
for (int i = 0; i < m_riserNumber - 1; i++)
{
XYZ start = new XYZ(0, i * m_desiredTreadDepth, m_bottomElevation);
XYZ end = start + m_widthOffset;
ret.Add(Line.CreateBound(start, end));
}
// last one handled manually to ensure that it intersects the endpoints of the stairs curves
// Untransformed curves are used because transformation happens below
IList<Curve> boundaryCurves = GenerateUntransformedRunBoundaryCurves();
ret.Add(Line.CreateBound(boundaryCurves[0].Evaluate(1.0, true), boundaryCurves[1].Evaluate(1.0, true)));
return Transform(ret);
}
}
}
@@ -0,0 +1,233 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs run consisting of a linear straight run.
/// </summary>
public class StraightStairsRunComponent : TransformedStairsComponent, IStairsRunComponent
{
/// <summary>
/// Creates a new straight stairs run in the default location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers.</param>
/// <param name="bottomElevation">The bottom elevation of the run.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width of the run.</param>
public StraightStairsRunComponent(int riserNumber, double bottomElevation, double desiredTreadDepth, double width):
base()
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_desiredTreadDepth = desiredTreadDepth;
m_width = width;
m_runOffset = new XYZ(0, (riserNumber - 1) * desiredTreadDepth, 0);
m_widthOffset = new XYZ(m_width, 0, 0);
}
/// <summary>
/// Creates a new straight stairs run in the specified location and orientation.
/// </summary>
/// <param name="riserNumber">The number of risers.</param>
/// <param name="bottomElevation">The bottom elevation of the run.</param>
/// <param name="desiredTreadDepth">The desired tread depth.</param>
/// <param name="width">The width of the run.</param>
/// <param name="transform">The transform (orientation and location) for the run.</param>
public StraightStairsRunComponent(int riserNumber, double bottomElevation, double desiredTreadDepth, double width,
Transform transform):
base (transform)
{
m_riserNumber = riserNumber;
m_bottomElevation = bottomElevation;
m_desiredTreadDepth = desiredTreadDepth;
m_width = width;
m_runOffset = new XYZ(0, (riserNumber - 1) * desiredTreadDepth, 0);
m_widthOffset = new XYZ(m_width, 0, 0);
}
private int m_riserNumber;
private double m_bottomElevation;
private double m_desiredTreadDepth;
private double m_width;
private XYZ m_runOffset;
private XYZ m_widthOffset;
private StairsRun m_stairsRun = null;
#region IStairsRunConfiguration Members
/// <summary>
/// Implements the interface method.
/// </summary>
public double GetRunElevation()
{
return m_bottomElevation;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Line GetRunStairsPath()
{
XYZ start = new XYZ(m_width / 2.0, 0, m_bottomElevation);
XYZ end = start + m_runOffset;
Line curve1 = Line.CreateBound(start, end);
return curve1;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public double RunElevation
{
get
{
return m_bottomElevation;
}
}
/// <summary>
/// Implements the interface method.
/// </summary>
public double TopElevation
{
get
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
return m_stairsRun.TopElevation;
}
}
/// <summary>
/// Implements the interface method.
/// </summary>
public IList<Curve> GetStairsPath()
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
CurveLoop curveLoop = m_stairsRun.GetStairsPath();
return curveLoop.ToList();
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetFirstCurve()
{
return GetEndCurve(false);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Curve GetLastCurve()
{
return GetEndCurve(true);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public XYZ GetRunEndpoint()
{
return GetLastCurve().GetEndPoint(0);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public Autodesk.Revit.DB.Architecture.StairsRun CreateStairsRun(Document document, ElementId stairsId)
{
m_stairsRun = StairsRun.CreateStraightRun(document, stairsId,
Transform(GetRunStairsPath()), StairsRunJustification.Center);
Width = m_width;
document.Regenerate(); // to get updated width
return m_stairsRun;
}
/// <summary>
/// Implements the interface property.
/// </summary>
public double Width
{
get
{
return m_width;
}
set
{
m_width = value;
if (m_stairsRun != null)
{
m_stairsRun.ActualRunWidth = m_width;
}
}
}
#endregion
/// <summary>
/// Gets the first or last riser curve of the run.
/// </summary>
/// <param name="last">True to get the last curve, false to get the first.</param>
/// <returns>The curve.</returns>
private Curve GetEndCurve(bool last)
{
if (m_stairsRun == null)
{
throw new NotSupportedException("Stairs run hasn't been constructed yet.");
}
// Obtain the footprint boundary of the run.
CurveLoop boundary = m_stairsRun.GetFootprintBoundary();
// Find the first or last point on the path
CurveLoop path = m_stairsRun.GetStairsPath();
Curve pathCurve = path.First<Curve>();
XYZ pathPoint = pathCurve.GetEndPoint(last ? 1 : 0);
// Walk the footprint boundary, and look for a curve whose projection of the target point is equal to the point.
foreach (Curve boundaryCurve in boundary)
{
if (boundaryCurve.Project(pathPoint).XYZPoint.IsAlmostEqualTo(pathPoint))
{
return boundaryCurve;
}
}
throw new Exception("Unable to find an intersecting boundary curve in the run.");
}
}
}
@@ -0,0 +1,93 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// An abstract base class for stairs components which can be moved via a translation and rotation.
/// </summary>
public class TransformedStairsComponent
{
private Transform m_transform;
/// <summary>
/// Constructs a transformed component with the identity transform.
/// </summary>
public TransformedStairsComponent()
{
m_transform = Autodesk.Revit.DB.Transform.Identity;
}
/// <summary>
/// Constructs a transformed component with the specified transform.
/// </summary>
public TransformedStairsComponent(Transform transform)
{
m_transform = transform;
}
/// <summary>
/// Transforms the given XYZ point by the stored transform.
/// </summary>
/// <param name="point">The point.</param>
/// <returns>The transformed point.</returns>
public XYZ TransformPoint(XYZ point)
{
XYZ xyz = m_transform.OfPoint(point);
return xyz;
}
/// <summary>
/// Transforms the given curve by the stored transform.
/// </summary>
/// <param name="curve">The curve.</param>
/// <returns>The transformed curve.</returns>
public Curve Transform(Curve curve)
{
return GeometryUtils.TransformCurve(curve, m_transform);
}
/// <summary>
/// Transforms the given line by the stored transform.
/// </summary>
/// <param name="line">The line.</param>
/// <returns>The transformed line.</returns>
public Line Transform(Line line)
{
return Transform(line as Curve) as Line;
}
/// <summary>
/// Transforms all members of the given curve array by the stored transform.
/// </summary>
/// <param name="inputs">The input curves.</param>
/// <returns>The transformed curves.</returns>
public IList<Curve> Transform(IList<Curve> inputs)
{
return GeometryUtils.TransformCurves(inputs, m_transform);
}
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
<AddIn Type="Command">
<Assembly>StairsAutomation.dll</Assembly>
<ClientId>4ce08562-a2e1-4cbf-816d-4923e1363a21</ClientId>
<FullClassName>Revit.SDK.Samples.StairsAutomation.CS.Command</FullClassName>
<Text>Stairs automation</Text>
<Description>A utility sample that creates a series of stairs, stairs runs and stairs landings configurations based upon predefined rules and parameters.</Description>
<VisibilityMode>AlwaysVisible</VisibilityMode>
<LanguageType>Unknown</LanguageType>
<VendorId>ADSK</VendorId>
</AddIn>
</RevitAddIns>
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3AFBB480-F48A-4E07-B20E-A776318404A6}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Revit.SDK.Samples.StairsAutomationSample.CS</RootNamespace>
<AssemblyName>StairsAutomation</AssemblyName>
<StartupObject>
</StartupObject>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DocumentationFile>bin\Debug\StairsAutomation.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DocumentationFile>bin\Debug\StairsAutomation.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Command.cs" />
<Compile Include="GeometryUtils.cs" />
<Compile Include="IStairsConfiguration.cs" />
<Compile Include="LandingComponents\IStairsLandingComponent.cs" />
<Compile Include="LandingComponents\LandingComponentUtils.cs" />
<Compile Include="LandingComponents\StairsRectangleLandingComponent.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RunComponents\CurvedStairsRunComponent.cs" />
<Compile Include="RunComponents\IStairsRunComponent.cs" />
<Compile Include="RunComponents\SketchedCurvedStairsRunComponent.cs" />
<Compile Include="RunComponents\SketchedStraightStairsRunComponent.cs" />
<Compile Include="RunComponents\StraightStairsRunComponent.cs" />
<Compile Include="RunComponents\TransformedStairsComponent.cs" />
<Compile Include="StairsAutomationUtility.cs" />
<Compile Include="StairsConfiguration.cs" />
<Compile Include="StairsSingleCurvedRun.cs" />
<Compile Include="StairsSingleSketchedCurvedRun.cs" />
<Compile Include="StairsSingleSketchedStraightRun.cs" />
<Compile Include="StairsSingleStraightRun.cs" />
<Compile Include="StairsStandardConfiguration.cs" />
</ItemGroup>
<Import Project="$(SolutionDir)VSProps\SDKSamples.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>set FILEFORSAMPLEREG="$(SolutionDir)..\..\..\..\Regression\API\SDKSamples\UpdateSampleDllForRegression.pl"
if exist %25FILEFORSAMPLEREG%25 perl %25FILEFORSAMPLEREG%25 $(ProjectExt) "$(ProjectPath)" "$(TargetPath)" "$(SolutionDir)"</PostBuildEvent>
</PropertyGroup>
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>
</Project>
@@ -0,0 +1,284 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// The main class governing the automatic stairs element creation.
/// </summary>
public class StairsAutomationUtility
{
private Autodesk.Revit.DB.Document document;
private Stairs m_stairs;
private int m_stairsNumber;
/// <summary>
/// The bottom level for the stairs assembly.
/// </summary>
public Autodesk.Revit.DB.Level BottomLevel { get; set; }
/// <summary>
/// The top level for the stairs assembly.
/// </summary>
public Autodesk.Revit.DB.Level TopLevel { get; set; }
/// <summary>
/// The document.
/// </summary>
protected Autodesk.Revit.DB.Document Document
{
get
{
return document;
}
}
/// <summary>
/// The stairs.
/// </summary>
protected Autodesk.Revit.DB.Architecture.Stairs Stairs
{
get
{
return m_stairs;
}
}
/// <summary>
/// Creates a new instance of this class for a given stairs congfiguration.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="stairsNumber">The stairs configuration number.</param>
protected StairsAutomationUtility(Autodesk.Revit.DB.Document document, int stairsNumber)
{
this.document = document;
this.m_stairsNumber = stairsNumber;
}
/// <summary>
/// Sets up a new stairs automation utility.
/// </summary>
/// <param name="document">The document in which the stairs will be created.</param>
/// <param name="stairsNumber">The predefined stairs configuration number.</param>
/// <returns></returns>
public static StairsAutomationUtility Create(Autodesk.Revit.DB.Document document, int stairsNumber)
{
StairsAutomationUtility utility = new StairsAutomationUtility(document, stairsNumber);
return utility;
}
#region LevelManagement
/// <summary>
/// Sets up the levels for the bottom and top of the stairs assembly.
/// </summary>
private void SetupLevels()
{
Tuple<Level, Level, Level> targetLevels = FindTargetLevels(document, "Level 1", "Level 2", "Level 3");
Level level1 = targetLevels.Item1;
Level level2 = targetLevels.Item2;
Level level3 = targetLevels.Item3;
switch (m_stairsNumber)
{
// Standard stair 1 level
case 3:
BottomLevel = level1;
TopLevel = level2;
break;
//Level 1 -> Level 3
default:
BottomLevel = level1;
TopLevel = level3;
break;
}
}
private static Tuple<Level, Level, Level> FindTargetLevels(Document doc, String name1, String name2, String name3)
{
FilteredElementCollector collector = new FilteredElementCollector(doc);
collector.OfClass(typeof(Level));
Level level1 = null;
Level level2 = null;
Level level3 = null;
foreach (Level level in collector.Cast<Level>().Where<Level>(level => level.Name.Equals(name1) || level.Name.Equals(name2) || level.Name.Equals(name3)))
{
if (level.Name.Equals(name1))
level1 = level;
else if (level.Name.Equals(name2))
level2 = level;
else
level3 = level;
}
return new Tuple<Level, Level, Level>(level1, level2, level3);
}
// Not currently used.
#if false
private static bool IsStoryLevel(Level level)
{
Parameter p = level.get_Parameter(BuiltInParameter.LEVEL_IS_BUILDING_STORY);
return (p != null && p.AsInteger() != 0);
}
private bool IsBetweenExtents(Level level)
{
if (level.Id == BottomLevel.Id || level.Id == TopLevel.Id)
return false;
return level.Elevation > BottomLevel.Elevation && level.Elevation < TopLevel.Elevation;
}
private IEnumerable<Level> FindStoryLevelsBetweenExtents()
{
FilteredElementCollector collector = new FilteredElementCollector(document);
collector.OfClass(typeof(Level));
return collector.Cast<Level>().Where<Level>(level => IsBetweenExtents(level) && IsStoryLevel(level));
}
#endif
#endregion
/// <summary>
/// Sets up and returns the hardcoded configuration corresponding to the stairs number.
/// </summary>
/// <remarks>Some configuration types will require the ability to make changes to the stairs element.
/// Thus, this method needs an open transaction.</remarks>
/// <returns></returns>
protected virtual IStairsConfiguration SetupHardcodedConfiguration()
{
switch (m_stairsNumber)
{
// Straight run 1 level
case 0:
{
var run = new StairsSingleStraightRun(m_stairs, BottomLevel, Transform.CreateTranslation(new XYZ(100, 0, 0)));
run.SetRunWidth(15.0);
return run;
}
// Curved run 1 level
case 1:
{
var run = new StairsSingleCurvedRun(m_stairs, BottomLevel, 6.0);
run.SetRunWidth(10.0);
return run;
}
// Curve run 2 level
case 2:
return new StairsSingleCurvedRun(m_stairs, BottomLevel, 3.0, Transform.CreateRotationAtPoint(XYZ.BasisZ, Math.PI, new XYZ(10, -20, 0)));
// Standard stair 1 level
case 3:
{
StairsStandardConfiguration configuration = new StairsStandardConfiguration(m_stairs, BottomLevel, 1, Transform.CreateRotationAtPoint(XYZ.BasisZ, Math.PI / 4.0, new XYZ(-20, -20, 0)));
configuration.EqualizeRuns = true;
configuration.Initialize();
return configuration;
}
// Standard stair multi-level
case 4:
{
StairsStandardConfiguration configuration = new StairsStandardConfiguration(m_stairs, BottomLevel, 3, Transform.CreateRotationAtPoint(XYZ.BasisZ, 7.0 * Math.PI / 6.0, new XYZ(15, 10, 0)));
configuration.RunWidth = 6.0;
configuration.RunOffset = 8.0 / 12.0;
configuration.LandingWidth = 4.0;
configuration.EqualizeRuns = true;
configuration.Initialize();
return configuration;
}
case 100:
{
return new StairsSingleSketchedStraightRun(m_stairs, BottomLevel, Transform.CreateTranslation(new XYZ(50, 0, 0)));
}
case 101:
{
return new StairsSingleSketchedCurvedRun(m_stairs, BottomLevel, 6.0, Transform.CreateTranslation(new XYZ(-10, 0, 0)));
}
}
return null;
}
/// <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());
}
}
}
class StairsEditScopeFailuresPreprocessor : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
return FailureProcessingResult.Continue;
}
}
}
@@ -0,0 +1,88 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A specific implementation of IStairsConfiguration with some default storage included.
/// </summary>
public class StairsConfiguration : IStairsConfiguration
{
/// <summary>
/// The run configurations.
/// </summary>
protected List<IStairsRunComponent> m_runConfigurations = new List<IStairsRunComponent>();
/// <summary>
/// The landing configurations.
/// </summary>
protected List<IStairsLandingComponent> m_landingConfigurations = new List<IStairsLandingComponent>();
#region IStairsConfiguration members
/// <summary>
/// Implements the interface method.
/// </summary>
public int GetNumberOfRuns()
{
return m_runConfigurations.Count;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public void CreateStairsRun(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.ElementId stairsElementId, int runIndex)
{
m_runConfigurations[runIndex].CreateStairsRun(document, stairsElementId);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public int GetNumberOfLandings()
{
return m_landingConfigurations.Count;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public void CreateLanding(Autodesk.Revit.DB.Document document, Autodesk.Revit.DB.ElementId stairsElementId, int landingIndex)
{
m_landingConfigurations[landingIndex].CreateLanding(document, stairsElementId);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public void SetRunWidth(double width)
{
foreach (var config in m_runConfigurations)
{
config.Width = width;
}
}
#endregion
}
}
@@ -0,0 +1,65 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs configuration representing a single curved run.
/// </summary>
/// <remarks>Because this run is based on Spiral runs, runs exceeding 360 degrees are possible.</remarks>
class StairsSingleCurvedRun : StairsConfiguration
{
/// <summary>
/// Creates a new instance of StairsSingleCurvedRun at the default location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
/// <param name="innerRadius">The inner radius of the run curvature.</param>
public StairsSingleCurvedRun(Stairs stairs, Level bottomLevel, double innerRadius)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add (new CurvedStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation, stairsType.MinTreadDepth, stairsType.MinRunWidth,
innerRadius, stairs.Document.Application.Create));
}
/// <summary>
/// Creates a new instance of StairsSingleCurvedRun at a specified location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
/// <param name="innerRadius">The inner radius of the run curvature.</param>
/// <param name="transform">The transform (containing location and orientation).</param>
public StairsSingleCurvedRun(Stairs stairs, Level bottomLevel, double innerRadius, Transform transform)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add (new CurvedStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation, stairsType.MinTreadDepth, stairsType.MinRunWidth,
innerRadius, stairs.Document.Application.Create, transform));
}
}
}
@@ -0,0 +1,70 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs configuration that represents a single curved run (which will be made in Revit as a sketched run).
/// </summary>
/// <remarks>Because this is a sketched run, a included angle of greater than 360 degrees will not succeed.</remarks>
class StairsSingleSketchedCurvedRun : StairsConfiguration
{
/// <summary>
/// Creates a new instance of StairsSingleSketchedCurvedRun at the default location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
/// <param name="innerRadius">The inner radius of the run curvature.</param>
public StairsSingleSketchedCurvedRun(Stairs stairs, Level bottomLevel, double innerRadius)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add(new SketchedCurvedStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation,
stairsType.MinTreadDepth, stairsType.MinRunWidth,
innerRadius, stairs.Document.Application.Create));
}
/// <summary>
/// Creates a new instance of StairsSingleSketchedCurvedRun at a specified location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
/// <param name="innerRadius">The inner radius of the run curvature.</param>
/// <param name="transform">The transform (containing location and orientation).</param>
public StairsSingleSketchedCurvedRun(Stairs stairs, Level bottomLevel, double innerRadius, Transform transform)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add(new SketchedCurvedStairsRunComponent(stairs.DesiredRisersNumber,
bottomLevel.Elevation, stairsType.MinTreadDepth,
stairsType.MinRunWidth, innerRadius,
stairs.Document.Application.Create,
transform));
}
}
}
@@ -0,0 +1,63 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs configuration that represents a single straight run (which will be made in Revit as a sketched run).
/// </summary>
public class StairsSingleSketchedStraightRun : StairsConfiguration
{
/// <summary>
/// Creates a new instance of StairsSingleSketchedStraightRun at the default location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
public StairsSingleSketchedStraightRun(Stairs stairs, Level bottomLevel)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add (new SketchedStraightStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation,
stairsType.MinTreadDepth, stairsType.MinRunWidth));
}
/// <summary>
/// Creates a new instance of StairsSingleSketchedStraightRun at a given location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
/// <param name="transform">The transform (containing location and orientation).</param>
public StairsSingleSketchedStraightRun(Stairs stairs, Level bottomLevel, Transform transform)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add (new SketchedStraightStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation,
stairsType.MinTreadDepth, stairsType.MinRunWidth,
transform));
}
}
}
@@ -0,0 +1,60 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// A stairs configuration representing a single straight run.
/// </summary>
public class StairsSingleStraightRun : StairsConfiguration
{
/// <summary>
/// Creates a new instance of StairsSingleStraightRun at the default location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
public StairsSingleStraightRun(Stairs stairs, Level bottomLevel)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add(new StraightStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation, stairsType.MinTreadDepth, stairsType.MinRunWidth));
}
/// <summary>
/// Creates a new instance of StairsSingleStraightRun at a given location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level of the configuration.</param>
/// <param name="transform">The transform (containing location and orientation).</param>
public StairsSingleStraightRun(Stairs stairs, Level bottomLevel, Transform transform)
{
StairsType stairsType = stairs.Document.GetElement(stairs.GetTypeId()) as StairsType;
m_runConfigurations.Add(new StraightStairsRunComponent(stairs.DesiredRisersNumber, bottomLevel.Elevation, stairsType.MinTreadDepth, stairsType.MinRunWidth, transform));
}
}
}
@@ -0,0 +1,341 @@
//
// (C) Copyright 2003-2019 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
namespace Revit.SDK.Samples.StairsAutomation.CS
{
/// <summary>
/// Represents a stairs configuration consisting of straight runs and rectangular landings. The runs will
/// switch based upon the input parameters. The landings width can be adjusted independently.
/// </summary>
public class StairsStandardConfiguration : IStairsConfiguration
{
List<IStairsRunComponent> m_runConfigurations = new List<IStairsRunComponent>();
List<IStairsLandingComponent> m_landingConfigurations = new List<IStairsLandingComponent>();
private int m_numberOfLandings;
private Stairs m_stairs;
private StairsType m_stairsType;
private double m_bottomElevation;
private Transform m_transform;
/// <summary>
/// The number of risers to include in the stairs.
/// </summary>
public int RiserNumber { get; set; }
private double m_runWidth;
private bool m_runWidthOverride = false;
private double m_runOffset;
private bool m_runOffsetOverride = false;
private double m_landingWidth;
private bool m_landingWidthOverride = false;
private int m_riserIncrement = 1;
/// <summary>
/// True to ensure that all runs have the same number of treads (which might require adjustment to the tread height to
/// compensate for the number of runs). False to allow a different number of treads (which practically, might result in
/// some runs getting one less tread than others).
/// </summary>
public bool EqualizeRuns { get; set; }
/// <summary>
/// The width of the landings. If not explicitly set, the width of the runs is used.
/// </summary>
public double LandingWidth
{
get
{
if (m_landingWidthOverride)
{
return m_landingWidth;
}
return RunWidth;
}
set
{
m_landingWidth = value;
m_landingWidthOverride = true;
}
}
/// <summary>
/// The width of the runs. If not explicitly set, the stairs type default width is used.
/// </summary>
public double RunWidth
{
get
{
if (m_runWidthOverride)
{
return m_runWidth;
}
return m_stairsType.MinRunWidth;
}
set
{
m_runWidth = value;
m_runWidthOverride = true;
}
}
/// <summary>
/// The offset between the corner of one run and the corner of the next during a switchback at a landing.
/// </summary>
public double RunOffset
{
get
{
if (m_runOffsetOverride)
{
return m_runOffset;
}
return 2.0;
}
set
{
m_runOffset = value;
m_runOffsetOverride = true;
}
}
/// <summary>
/// Creates a new StairsStandardConfiguration of runs and landings at the default location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level.</param>
/// <param name="numberOfLandings">The number of landings to be included.</param>
public StairsStandardConfiguration(Stairs stairs, Level bottomLevel, int numberOfLandings)
{
m_stairs = stairs;
m_stairsType = m_stairs.Document.GetElement(m_stairs.GetTypeId()) as StairsType;
m_bottomElevation = bottomLevel.Elevation;
RiserNumber = stairs.DesiredRisersNumber;
m_numberOfLandings = numberOfLandings;
m_transform = Transform.Identity;
EqualizeRuns = false;
}
/// <summary>
/// Creates a new StairsStandardConfiguration of runs and landings at a specified location and orientation.
/// </summary>
/// <param name="stairs">The stairs element.</param>
/// <param name="bottomLevel">The bottom level.</param>
/// <param name="numberOfLandings">The number of landings to be included.</param>
/// <param name="transform">The transformation (location and orientation).</param>
public StairsStandardConfiguration(Stairs stairs, Level bottomLevel, int numberOfLandings, Transform transform)
{
m_stairs = stairs;
m_stairsType = m_stairs.Document.GetElement(m_stairs.GetTypeId()) as StairsType;
m_bottomElevation = bottomLevel.Elevation;
RiserNumber = stairs.DesiredRisersNumber;
m_numberOfLandings = numberOfLandings;
m_transform = transform;
EqualizeRuns = false;
}
/// <summary>
/// Initializes the run and landing data in the configuration.
/// </summary>
public void Initialize()
{
if (m_numberOfLandings < 0)
{
throw new ArgumentOutOfRangeException("numberOfLandings", "Number of landings must be 0 or more");
}
if (m_numberOfLandings > RiserNumber)
{
throw new ArgumentOutOfRangeException("numberOfLandings", "Number of landings must be less than calculated riser number for the stairs");
}
if (EqualizeRuns)
{
int remainder = RiserNumber % (m_numberOfLandings + 1);
if (remainder != 0)
{
m_stairs.DesiredRisersNumber = m_stairs.DesiredRisersNumber + m_numberOfLandings + 1 - remainder;
m_stairs.Document.Regenerate();
RiserNumber = m_stairs.DesiredRisersNumber;
}
}
// Split as evenly as possible
m_riserIncrement = RiserNumber / (m_numberOfLandings + 1);
}
/// <summary>
/// Generates the landing configuration for the end lines of 2 risers.
/// </summary>
/// <param name="riser1Line">The end line of the first riser.</param>
/// <param name="riser2Line">The start line of the second riser.</param>
/// <param name="runDirection">The run direction.</param>
/// <param name="landingElevation">The elevation.</param>
/// <returns>The landing configuration.</returns>
public virtual IStairsLandingComponent GenerateLanding(Line riser1Line, Line riser2Line, XYZ runDirection, double landingElevation)
{
IStairsLandingComponent landingConfiguration = new StairsRectangleLandingComponent(riser1Line, riser2Line, runDirection, landingElevation, LandingWidth);
return landingConfiguration;
}
/// <summary>
/// Generates the run configuration for the given elevation and properties.
/// </summary>
/// <param name="numberOfRisers">The number of risers in the run.</param>
/// <param name="elevation">The start elevation.</param>
/// <param name="minTreadDepth">The minimum tread depth.</param>
/// <param name="runWidth">The width of the run.</param>
/// <param name="transform">The transformation applied to the run start point and orientation.</param>
/// <returns></returns>
public virtual IStairsRunComponent GenerateRun(int numberOfRisers, double elevation, double minTreadDepth,
double runWidth, Transform transform)
{
IStairsRunComponent run = new StraightStairsRunComponent(numberOfRisers, elevation,
minTreadDepth, runWidth, transform);
return run;
}
/// <summary>
/// A helper to obtain the Autodesk.Revit.Creation.Application handle.
/// </summary>
protected Autodesk.Revit.Creation.Application AppCreate
{
get
{
return m_stairs.Document.Application.Create;
}
}
#region IStairsConfiguration Members
/// <summary>
/// Implements the interface method.
/// </summary>
public int GetNumberOfRuns()
{
return m_numberOfLandings + 1;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public int GetNumberOfLandings()
{
return m_numberOfLandings;
}
/// <summary>
/// Implements the interface method.
/// </summary>
public void CreateStairsRun(Document document, ElementId stairsElementId, int runIndex)
{
// Calculate where the previous run ended.
XYZ previousRunEndPoint = runIndex == 0 ? XYZ.Zero : m_runConfigurations[runIndex - 1].GetRunEndpoint();
double elevation = runIndex == 0 ? m_bottomElevation : m_runConfigurations[runIndex - 1].TopElevation;
// Setup number of risers for the run.
int runNumberOfRisers = m_riserIncrement;
if (runIndex == m_numberOfLandings)
{
runNumberOfRisers = RiserNumber - m_numberOfLandings * m_riserIncrement;
}
// Setup the transform for the run. Every second run must be reversed in direction and start point generated from
// the offet to the previous run.
Transform transform = Transform.Identity;
XYZ pivotPoint = previousRunEndPoint + m_transform.OfPoint(new XYZ(RunWidth + RunOffset, 0, 0));
if (runIndex % 2 == 1)
{
Transform translation = Transform.CreateTranslation(pivotPoint);
Transform rotation = Transform.CreateRotationAtPoint(XYZ.BasisZ, Math.PI, pivotPoint);
transform = rotation.Multiply(translation);
}
transform = transform.Multiply(m_transform);
// Generate the run configuration and it.
IStairsRunComponent configuration = GenerateRun(runNumberOfRisers, elevation,
m_stairsType.MinTreadDepth, RunWidth, transform);
m_runConfigurations.Add(configuration);
// Create the run now (subsequent runs and landings need to use its geometric properties).
configuration.CreateStairsRun(document, stairsElementId);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public void CreateLanding(Document document, ElementId stairsElementId, int landingIndex)
{
// Get the run configurations for the runs before and after this landing.
IStairsRunComponent configuration1 = m_runConfigurations[landingIndex];
IStairsRunComponent configuration2 = m_runConfigurations[landingIndex + 1];
// Get the stairs path from the lower run for run direction.
Curve curve = configuration1.GetStairsPath()[0];
XYZ runDirection = (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize();
// Generate the landing configuration
IStairsLandingComponent configuration = GenerateLanding(configuration1.GetLastCurve() as Line,
configuration2.GetFirstCurve() as Line,
runDirection,
configuration2.RunElevation);
m_landingConfigurations.Add(configuration);
// Create the landing now
configuration.CreateLanding(document, stairsElementId);
}
/// <summary>
/// Implements the interface method.
/// </summary>
public void SetRunWidth(double value)
{
//cache width for new runs.
RunWidth = value;
//assign to existing run configurations
foreach (var config in m_runConfigurations)
{
config.Width = value;
}
}
#endregion
/// <summary>
/// Returns the transform assigned to the configuration.
/// </summary>
/// <returns>The transform.</returns>
protected Transform GetTransform()
{
return m_transform;
}
}
}