Skip to content

Commit

Permalink
Add CreateLines in ShapeCreator
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Jun 14, 2024
1 parent d8bde07 commit b321a72
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Add `ColorExtension` with `ColorEquals`, `Lerp`, `ToColor` and `ToColorWithTransparency`.
- Add `ColorExtension` with `ToHex` for `Color` and `ColorWithTransparency`
- Update `CreateBoxLines` with `graphicsStyleId`
- Add `CreateLines` in `ShapeCreator`
### Tests
- Test all color names in `System.Windows.Media.Colors` with `Colors`.
- Test all 9 colors in `MaterialUtils` and `GraphicsStyleUtils`.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.3.2-rc.3</Version>
<Version>0.3.2-rc.4</Version>
<RevitVersionTests>2024</RevitVersionTests>
<RevitVersionCoreTests>2025</RevitVersionCoreTests>
<RevitForceOpenClose>true</RevitForceOpenClose>
Expand Down
58 changes: 56 additions & 2 deletions ricaun.Revit.DB.Shape/ShapeCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,59 @@ public static class ShapeCreator
/// Default Sides for Prisms and Pyramids.
/// </summary>
internal const int Sides = 3;
#region Box

#region Lines
/// <summary>
/// Creates an array of <see cref="Line"/> objects from a collection of <see cref="Autodesk.Revit.DB.XYZ"/> points.
/// </summary>
/// <param name="points">A collection of <see cref="Autodesk.Revit.DB.XYZ"/> points to create lines from.</param>
/// <param name="closed">
/// A boolean value indicating whether the lines should form a closed loop.
/// If true, an additional line will be created from the last point back to the first point.
/// </param>
/// <returns>
/// An array of <see cref="Line"/> objects representing the lines created from the specified points.
/// </returns>
public static Line[] CreateLines(IEnumerable<XYZ> points, bool closed)
{
return CreateLines(points, null, closed);
}
/// <summary>
/// Creates an array of <see cref="Line"/> objects from a collection of <see cref="Autodesk.Revit.DB.XYZ"/> points.
/// </summary>
/// <param name="points">A collection of <see cref="Autodesk.Revit.DB.XYZ"/> points to create lines from.</param>
/// <param name="graphicsStyleId">
/// An optional <see cref="Autodesk.Revit.DB.ElementId"/> representing the graphics style to apply to the lines.
/// If null, the default graphics style will be used.
/// </param>
/// <param name="closed">
/// A boolean value indicating whether the lines should form a closed loop.
/// If true, an additional line will be created from the last point back to the first point.
/// </param>
/// <returns>
/// An array of <see cref="Line"/> objects representing the lines created from the specified points.
/// </returns>
public static Line[] CreateLines(IEnumerable<XYZ> points, ElementId graphicsStyleId = null, bool closed = false)
{
var lines = new List<Line>();
var pointsArray = points.ToArray();

for (int i = 0; i < pointsArray.Length - 1; i++)
{
var line = CreateBound(pointsArray[i], pointsArray[i + 1], graphicsStyleId);
if (line is not null)
lines.Add(line);
}

if (closed)
{
var line = CreateBound(pointsArray[0], pointsArray[pointsArray.Length - 1], graphicsStyleId);
if (line is not null)
lines.Add(line);
}

return lines.ToArray();
}
/// <summary>
/// Creates an array of lines representing the edges of a 3D box with the specified minimum and maximum points.
/// </summary>
Expand Down Expand Up @@ -64,7 +116,7 @@ public static Line[] CreateBoxLines(XYZ min, XYZ max, ElementId graphicsStyleId

return lines.OfType<Line>().ToArray();
}
private static Line CreateBound(XYZ point1, XYZ point2, ElementId graphicsStyleId = null)
internal static Line CreateBound(XYZ point1, XYZ point2, ElementId graphicsStyleId = null)
{
try
{
Expand All @@ -78,6 +130,8 @@ private static Line CreateBound(XYZ point1, XYZ point2, ElementId graphicsStyleI
catch { }
return null;
}
#endregion
#region Box
/// <summary>
/// Creates a 3D box with the specified center and size.
/// </summary>
Expand Down

0 comments on commit b321a72

Please sign in to comment.