Skip to content

Commit

Permalink
Update CreateBoxLines with graphicsStyleId
Browse files Browse the repository at this point in the history
  • Loading branch information
ricaun committed Jun 14, 2024
1 parent d79dd2a commit d8bde07
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.3.2] / 2024-06-14
### Features
### Shapes
- Update Colors using the `System.Windows.Media.Colors` as reference.
- Update `MaterialUtils` and `GraphicsStyleUtils` with default 9 colors.
- Add `ColorExtension` with `ColorEquals`, `Lerp`, `ToColor` and `ToColorWithTransparency`.
- Add `ColorExtension` with `ToHex` for `Color` and `ColorWithTransparency`
- Update `CreateBoxLines` with `graphicsStyleId`
### 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.2</Version>
<Version>0.3.2-rc.3</Version>
<RevitVersionTests>2024</RevitVersionTests>
<RevitVersionCoreTests>2025</RevitVersionCoreTests>
<RevitForceOpenClose>true</RevitForceOpenClose>
Expand Down
23 changes: 15 additions & 8 deletions ricaun.Revit.DB.Shape/ShapeCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,23 @@ public static class ShapeCreator
/// </summary>
/// <param name="center">The center point of the box.</param>
/// <param name="scaleRadius">The scale size of the box.</param>
/// <param name="graphicsStyleId">The ID of the graphics style to use for the lines. If not specified, the lines will use the default graphics style.</param>
/// <returns>An array of lines representing the edges of the 3D box.</returns>
public static Line[] CreateBoxLines(XYZ center, double scaleRadius)
public static Line[] CreateBoxLines(XYZ center, double scaleRadius, ElementId graphicsStyleId = null)
{
var scaleXYZ = new XYZ(scaleRadius, scaleRadius, scaleRadius);
return CreateBoxLines(center - scaleXYZ, center + scaleXYZ);
return CreateBoxLines(center - scaleXYZ, center + scaleXYZ, graphicsStyleId);
}

/// <summary>
/// Creates an array of lines representing the edges of a 3D box with the specified minimum and maximum points.
/// </summary>
/// <param name="min">The minimum point of the box. This point defines the lower corner of the box.</param>
/// <param name="max">The maximum point of the box. This point defines the upper corner of the box.</param>
/// <param name="graphicsStyleId">The ID of the graphics style to use for the lines. If not specified, the lines will use the default graphics style.</param>
/// <returns>An array of lines representing the edges of the 3D box.</returns>
/// <remarks>Ignore Lines with distance too short.</remarks>
public static Line[] CreateBoxLines(XYZ min, XYZ max)
public static Line[] CreateBoxLines(XYZ min, XYZ max, ElementId graphicsStyleId = null)
{
// Create an array to store the lines
Line[] lines = new Line[12];
Expand All @@ -55,18 +57,23 @@ public static Line[] CreateBoxLines(XYZ min, XYZ max)
// Create the lines for each edge of the cube using a for loop
for (int i = 0; i < 4; i++)
{
lines[i] = CreateBound(vertices[i], vertices[(i + 1) % 4]);
lines[i + 4] = CreateBound(vertices[i], vertices[i + 4]);
lines[i + 8] = CreateBound(vertices[i + 4], vertices[(i + 1) % 4 + 4]);
lines[i] = CreateBound(vertices[i], vertices[(i + 1) % 4], graphicsStyleId);
lines[i + 4] = CreateBound(vertices[i], vertices[i + 4], graphicsStyleId);
lines[i + 8] = CreateBound(vertices[i + 4], vertices[(i + 1) % 4 + 4], graphicsStyleId);
}

return lines.OfType<Line>().ToArray();
}
private static Line CreateBound(XYZ point1, XYZ point2)
private static Line CreateBound(XYZ point1, XYZ point2, ElementId graphicsStyleId = null)
{
try
{
return Line.CreateBound(point1, point2);
var line = Line.CreateBound(point1, point2);

if (graphicsStyleId is not null)
line.SetGraphicsStyleId(graphicsStyleId);

return line;
}
catch { }
return null;
Expand Down

0 comments on commit d8bde07

Please sign in to comment.