Skip to content

Commit 0b38b5d

Browse files
authored
Merge pull request #19 from chuongmep/dev
Add Support Visualize Connector, Geometry Support
2 parents fe9ca76 + a9f5535 commit 0b38b5d

37 files changed

+2961
-99
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,5 @@ MigrationBackup/
356356
output/
357357
wix/
358358
_build
359+
360+
*.0001.rvt

CONTRIBUTING.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313

1414
Debugging:
1515

16-
- Run **Debug Profile** in Visual Studio or **Run Configuration** in JetBrains Rider. The required files have been added. All project files will be automatically copied to the Revit plugins folder.
16+
- Run **Debug Profile** in Visual Studio or **Run Configuration** in JetBrains Rider. The required files have been
17+
added. All project files will be automatically copied to the Revit plugins folder.
1718

1819
Creating a package:
1920

@@ -23,6 +24,23 @@ Creating a package:
2324
- The generated package will be in the **output** folder.
2425

2526
---
27+
28+
### Documentation and comments
29+
30+
- Document your code write with English language and use [Jupyter Book](https://jupyterbook.org/en/stable/intro.html) to
31+
generate the documentation. Please use branch.
32+
**docs** to collaborate with the documentation.
33+
34+
### Unit tests
35+
36+
- The [Revit Test Framework](https://github.com/DynamoDS/RevitTestFramework) (RTF) allows for remote testing on Revit.
37+
RTF creates a journal file for running Revit, specifies a model for it to open, and a specific test or fixture of
38+
tests to run. A model can also be specified to open before testing to run several tests with.
39+
- Write unit tests for your code. Please use branch **dev** to collaborate with the tests and write them in the
40+
**OpenMEPTest** project.
41+
42+
![](docs/img/RevitTestFrameworkGUI.png)
43+
2644
#### Please avoid:
2745

2846
- Lots of unrelated changes in one commit.

OpenMEP.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
1212
docs\OpenMEP_DynamoCustomization.xml = docs\OpenMEP_DynamoCustomization.xml
1313
docs\OpenMEPSandbox_DynamoCustomization.xml = docs\OpenMEPSandbox_DynamoCustomization.xml
1414
docs\sandbox\pkg.json = docs\sandbox\pkg.json
15+
CONTRIBUTING.md = CONTRIBUTING.md
1516
EndProjectSection
1617
EndProject
1718
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeployInstaller", "DeployInstaller\DeployInstaller.csproj", "{C7835EFE-E1C7-48B2-90D0-E943D43A905D}"

OpenMEP/ConnectorManager/Connector.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class Connector
1717
{
1818
private Connector()
1919
{
20-
2120
}
2221

2322
/// <summary>
@@ -206,7 +205,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
206205

207206
return Farthest;
208207
}
209-
208+
210209
/// <summary>
211210
/// Return Farthest Connector between element1 with element2
212211
/// </summary>
@@ -220,7 +219,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
220219
Autodesk.Revit.DB.Connector? connector = GetConnectorFarthest(element2, connectorSet);
221220
return connector;
222221
}
223-
222+
224223
/// <summary>
225224
/// Get Farthest Connector With Element
226225
/// </summary>
@@ -245,6 +244,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
245244
}
246245
}
247246
}
247+
248248
return farthest;
249249
}
250250

@@ -291,7 +291,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
291291
if (connectorManager == null) throw new ArgumentNullException(nameof(connectorManager));
292292
return GetUnusedConnectors(connectorManager);
293293
}
294-
294+
295295
/// <summary>
296296
/// return list connector used from element
297297
/// </summary>
@@ -301,7 +301,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
301301
{
302302
if (element == null) throw new ArgumentNullException(nameof(element));
303303
if (GetConnectors(element).Any()) return new List<Autodesk.Revit.DB.Connector?>();
304-
return GetConnectors(element).Where(x=>x!.IsConnected).ToList();
304+
return GetConnectors(element).Where(x => x!.IsConnected).ToList();
305305
}
306306

307307
/// <summary>
@@ -604,10 +604,11 @@ public static double AssignedKCoefficient(Autodesk.Revit.DB.Connector connector)
604604
if (connector.IsConnected)
605605
{
606606
return connector.AllRefs.Cast<Autodesk.Revit.DB.Connector>()
607-
.Where(x=>x.Owner.Id!=connector.Owner.Id)
607+
.Where(x => x.Owner.Id != connector.Owner.Id)
608608
.Where(x => x.ConnectorType != ConnectorType.Logical)
609609
.Select(x => x.Owner.ToDynamoType()).FirstOrDefault();
610610
}
611+
611612
return null;
612613
}
613614

@@ -838,4 +839,48 @@ public static Autodesk.Revit.DB.Connector ConnectTo(Autodesk.Revit.DB.Connector
838839
TransactionManager.Instance.TransactionTaskDone();
839840
return connector;
840841
}
842+
843+
/// <summary>
844+
/// Shows scalable lines representing the CoordinateSystem of a Connector.
845+
/// </summary>
846+
/// <param name="connector">Autodesk.Revit.DB.Connector</param>
847+
/// <param name="length">double</param>
848+
/// <returns name="Display">GeometryColor order by x,y,z</returns>
849+
/// <returns name="Origin">Point</returns>
850+
/// <returns name="XAxis">Vector(Red color)</returns>
851+
/// <returns name="YAxis">Vector(Green color)</returns>
852+
/// <returns name="ZAxis">Vector(Blue color)</returns>
853+
/// <returns name="XYPlane">Plane(Red-Green color)</returns>
854+
/// <returns name="YZPlane">Plane(Green-Blue color)</returns>
855+
/// <returns name="ZXPlane">Plane(Blue-Red color)</returns>
856+
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "ZAxis", "XYPlane", "YZPlane", "ZXPlane"})]
857+
public static Dictionary<string, object?> Display(Autodesk.Revit.DB.Connector? connector, double length = 1000)
858+
{
859+
if (length <= 0)
860+
{
861+
length = 1;
862+
}
863+
864+
if (connector == null) return new Dictionary<string, object?>();
865+
var origin = connector.Origin.ToDynamoType();
866+
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
867+
#if R20
868+
DisplayUnitType unitTypeId = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits;
869+
double xUnits = UnitUtils.ConvertFromInternalUnits(origin.X, unitTypeId);
870+
double yUnits = UnitUtils.ConvertFromInternalUnits(origin.Y, unitTypeId);
871+
double zUnits = UnitUtils.ConvertFromInternalUnits(origin.Z, unitTypeId);
872+
#else
873+
ForgeTypeId unitTypeId = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId();
874+
double xUnits = UnitUtils.ConvertFromInternalUnits(origin.X, unitTypeId);
875+
double yUnits = UnitUtils.ConvertFromInternalUnits(origin.Y, unitTypeId);
876+
double zUnits = UnitUtils.ConvertFromInternalUnits(origin.Z, unitTypeId);
877+
#endif
878+
879+
Point point = Autodesk.DesignScript.Geometry.Point.ByCoordinates(xUnits, yUnits, zUnits);
880+
var X = connector.CoordinateSystem.BasisX.ToDynamoVector();
881+
var Y = connector.CoordinateSystem.BasisY.ToDynamoVector();
882+
var Z = connector.CoordinateSystem.BasisZ.ToDynamoVector();
883+
CoordinateSystem coordinateSystem = Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(point, X, Y, Z);
884+
return OpenMEPSandbox.Geometry.CoordinateSystem.Display(coordinateSystem,length);
885+
}
841886
}

OpenMEP/ConnectorManager/ConnectorManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public static Revit.Elements.Element Owner( Autodesk.Revit.DB.ConnectorManager c
7171
/// </summary>
7272
/// <param name="connectorManager">connector manager</param>
7373
/// <returns name="connectors">a collections of connector manager</returns>
74-
public static List<Autodesk.Revit.DB.Connector> Connectors( Autodesk.Revit.DB.ConnectorManager connectorManager)
74+
public static List<Autodesk.Revit.DB.Connector> Connectors( Autodesk.Revit.DB.ConnectorManager? connectorManager)
7575
{
7676
List<Autodesk.Revit.DB.Connector> connectors = new List<Autodesk.Revit.DB.Connector>();
7777
ConnectorSet connectorSet = connectorManager.Connectors;

OpenMEP/OpenMEP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynVersion).*">
114114
<ExcludeAssets>runtime</ExcludeAssets>
115115
</PackageReference>
116+
<PackageReference Include="DynamoVisualProgramming.DynamoCoreNodes" Version="$(DynVersion).*" />
116117
<PackageReference Include="DynamoVisualProgramming.Revit" Version="$(DynVersion).*">
117118
<ExcludeAssets>runtime</ExcludeAssets>
118119
</PackageReference>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using Autodesk.DesignScript.Runtime;
2+
3+
namespace OpenMEPSandbox.Geometry;
4+
5+
public class CoordinateSystem
6+
{
7+
private CoordinateSystem()
8+
{
9+
}
10+
11+
/// <summary>
12+
/// Shows scalable lines representing the CoordinateSystem axes and rectangles for the planes
13+
/// </summary>
14+
/// <param name="coordinateSystem">Autodesk.DesignScript.Geometry.CoordinateSystem</param>
15+
/// <param name="length">double</param>
16+
/// <returns name="Display">GeometryColor</returns>
17+
/// <returns name="Origin">Point</returns>
18+
/// <returns name="XAxis">Vector</returns>
19+
/// <returns name="YAxis">Vector</returns>
20+
/// <returns name="ZAxis">Vector</returns>
21+
/// <returns name="XYPlane">Plane</returns>
22+
/// <returns name="YZPlane">Plane</returns>
23+
/// <returns name="ZXPlane">Plane</returns>
24+
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "ZAxis", "XYPlane", "YZPlane", "ZXPlane"})]
25+
public static Dictionary<string, object?> Display(Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem,
26+
double length = 1000)
27+
{
28+
if (length <= 0)
29+
{
30+
length = 1;
31+
}
32+
var pt = coordinateSystem.Origin;
33+
var lineX = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, coordinateSystem.XAxis, length);
34+
var colorX = DSCore.Color.ByARGB(255, 255, 0, 0);
35+
var lineY = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, coordinateSystem.YAxis, length);
36+
var colorY = DSCore.Color.ByARGB(255, 0, 255, 0);
37+
var lineZ = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, coordinateSystem.ZAxis, length);
38+
var colorZ = DSCore.Color.ByARGB(255, 0, 0, 255);
39+
List<Modifiers.GeometryColor> display = new List<Modifiers.GeometryColor>();
40+
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineX, colorX));
41+
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineY, colorY));
42+
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineZ, colorZ));
43+
var d = new Dictionary<string, object?>();
44+
d.Add("Display", display);
45+
d.Add("Origin", pt);
46+
d.Add("XAxis", coordinateSystem.XAxis);
47+
d.Add("YAxis", coordinateSystem.YAxis);
48+
d.Add("ZAxis", coordinateSystem.ZAxis);
49+
d.Add("XYPlane", coordinateSystem.XYPlane);
50+
d.Add("YZPlane", coordinateSystem.YZPlane);
51+
d.Add("ZXPlane", coordinateSystem.ZXPlane);
52+
return d;
53+
}
54+
}

OpenMEPSandbox/Geometry/Plane.cs

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,52 @@
1-
namespace OpenMEPSandbox.Geometry;
1+
using Autodesk.DesignScript.Geometry;
2+
using Autodesk.DesignScript.Runtime;
3+
4+
namespace OpenMEPSandbox.Geometry;
25

36
public class Plane
47
{
58
private Plane()
69
{
7-
10+
}
11+
12+
/// <summary>
13+
/// Shows scalable lines representing the axes and a rectangle for the Plane
14+
/// </summary>
15+
/// <param name="plane">Autodesk.DesignScript.Geometry.Plane</param>
16+
/// <param name="length">double</param>
17+
/// <returns name="Display">GeometryColor</returns>
18+
/// <returns name="Origin">Point</returns>
19+
/// <returns name="XAxis">Vector</returns>
20+
/// <returns name="YAxis">Vector</returns>
21+
/// <returns name="Normal">Vector</returns>
22+
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "Normal"})]
23+
public static Dictionary<string, object?> Display(Autodesk.DesignScript.Geometry.Plane? plane, double length = 1000)
24+
{
25+
if (length <= 0)
26+
{
27+
length = 1;
28+
}
29+
if (plane == null) return new Dictionary<string, object?>();
30+
var pt = plane.Origin;
31+
var lineX = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, plane.XAxis, length);
32+
var colorX = DSCore.Color.ByARGB(255, 255, 0, 0);
33+
var lineY = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, plane.YAxis, length);
34+
var colorY = DSCore.Color.ByARGB(255, 0, 255, 0);
35+
var lineN = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, plane.Normal, length);
36+
var colorN = DSCore.Color.ByARGB(255, 0, 0, 255);
37+
var rect = Rectangle.ByWidthLength(plane, length, length);
38+
var colorR = DSCore.Color.ByARGB(50, 50, 50, 50);
39+
List<Modifiers.GeometryColor> display = new List<Modifiers.GeometryColor>();
40+
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineX, colorX));
41+
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineY, colorY));
42+
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineN, colorN));
43+
display.Add(Modifiers.GeometryColor.ByGeometryColor(rect, colorR));
44+
var d = new Dictionary<string, object?>();
45+
d.Add("Display", display);
46+
d.Add("Origin", pt);
47+
d.Add("XAxis", plane.XAxis);
48+
d.Add("YAxis", plane.YAxis);
49+
d.Add("Normal", plane.Normal);
50+
return d;
851
}
952
}

OpenMEPSandbox/Geometry/Vector.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Dynamo.Graph.Nodes;
1+
using Autodesk.DesignScript.Runtime;
2+
using Dynamo.Graph.Nodes;
23

34
namespace OpenMEPSandbox.Geometry;
45

@@ -32,5 +33,36 @@ public static bool IsOppositeDirection(Autodesk.DesignScript.Geometry.Vector v1,
3233
return (v1.Normalized().Dot(v2.Normalized())).Equals(-1);
3334
}
3435

36+
/// <summary>
37+
/// Shows a scalable line representing a Vector from a chosen starting point
38+
/// </summary>
39+
/// <param name="vector">Autodesk.DesignScript.Geometry.Vector</param>
40+
/// <param name="startPoint">Autodesk.DesignScript.Geometry.Point</param>
41+
/// <param name="scale">value scale start from 1</param>
42+
/// <returns name="Display">GeometryColor</returns>
43+
/// <returns name="X">double</returns>
44+
/// <returns name="Y">double</returns>
45+
/// <returns name="Z">double</returns>
46+
/// <returns name="Length">double</returns>
47+
[MultiReturn(new[] { "Display", "X", "Y", "Z", "Length" })]
48+
public static Dictionary<string, object?> Display(Autodesk.DesignScript.Geometry.Vector vector, Autodesk.DesignScript.Geometry.Point startPoint, double scale = 1000)
49+
{
50+
if (scale <= 0)
51+
{
52+
scale = 1;
53+
}
54+
var line = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(startPoint, vector, vector.Length * scale);
55+
var color = DSCore.Color.ByARGB(255, 255, 0, 0);
56+
List<Modifiers.GeometryColor> display = new List<Modifiers.GeometryColor>();
57+
display.Add(Modifiers.GeometryColor.ByGeometryColor(line, color));
58+
var d = new Dictionary<string, object?>();
59+
d.Add("Display", display);
60+
d.Add("X", vector.X);
61+
d.Add("Y", vector.Y);
62+
d.Add("Z", vector.Z);
63+
d.Add("Length", vector.Length);
64+
return d;
65+
}
66+
3567

3668
}

OpenMEPSandbox/OpenMEPSandbox.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
</PropertyGroup>
105105
<ItemGroup>
106106
<PackageReference Include="GShark" Version="2.2.0" />
107+
<PackageReference Include="DynamoVisualProgramming.DynamoCoreNodes" Version="$(DynVersion).*" />
107108
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynVersion).*">
108109
<ExcludeAssets>runtime</ExcludeAssets>
109110
</PackageReference>

0 commit comments

Comments
 (0)