-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25bf288
commit 0ff2329
Showing
25 changed files
with
7,626 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// (C) Copyright 2003-2017 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 }; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// (C) Copyright 2003-2017 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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// (C) Copyright 2003-2017 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// (C) Copyright 2003-2017 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// (C) Copyright 2003-2017 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; | ||
} | ||
} | ||
} |
Oops, something went wrong.