From d8bde071b92336e3cbf116c8d85270a559cab47f Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Fri, 14 Jun 2024 15:49:23 -0300 Subject: [PATCH] Update `CreateBoxLines` with `graphicsStyleId` --- CHANGELOG.md | 3 ++- Directory.Build.props | 2 +- ricaun.Revit.DB.Shape/ShapeCreator.cs | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccf113f..50e3823 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/Directory.Build.props b/Directory.Build.props index 156d645..e576d89 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 0.3.2-rc.2 + 0.3.2-rc.3 2024 2025 true diff --git a/ricaun.Revit.DB.Shape/ShapeCreator.cs b/ricaun.Revit.DB.Shape/ShapeCreator.cs index 0025c07..d7b2cf3 100644 --- a/ricaun.Revit.DB.Shape/ShapeCreator.cs +++ b/ricaun.Revit.DB.Shape/ShapeCreator.cs @@ -21,11 +21,12 @@ public static class ShapeCreator /// /// The center point of the box. /// The scale size of the box. + /// The ID of the graphics style to use for the lines. If not specified, the lines will use the default graphics style. /// An array of lines representing the edges of the 3D box. - 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); } /// @@ -33,9 +34,10 @@ public static Line[] CreateBoxLines(XYZ center, double scaleRadius) /// /// The minimum point of the box. This point defines the lower corner of the box. /// The maximum point of the box. This point defines the upper corner of the box. + /// The ID of the graphics style to use for the lines. If not specified, the lines will use the default graphics style. /// An array of lines representing the edges of the 3D box. /// Ignore Lines with distance too short. - 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]; @@ -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().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;