Skip to content

Commit

Permalink
Merge pull request #19 from chuongmep/dev
Browse files Browse the repository at this point in the history
Add Support Visualize Connector, Geometry Support
  • Loading branch information
chuongmep authored Feb 28, 2023
2 parents fe9ca76 + a9f5535 commit 0b38b5d
Show file tree
Hide file tree
Showing 37 changed files with 2,961 additions and 99 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,5 @@ MigrationBackup/
output/
wix/
_build

*.0001.rvt
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

Debugging:

- 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.
- 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.

Creating a package:

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

---

### Documentation and comments

- Document your code write with English language and use [Jupyter Book](https://jupyterbook.org/en/stable/intro.html) to
generate the documentation. Please use branch.
**docs** to collaborate with the documentation.

### Unit tests

- The [Revit Test Framework](https://github.com/DynamoDS/RevitTestFramework) (RTF) allows for remote testing on Revit.
RTF creates a journal file for running Revit, specifies a model for it to open, and a specific test or fixture of
tests to run. A model can also be specified to open before testing to run several tests with.
- Write unit tests for your code. Please use branch **dev** to collaborate with the tests and write them in the
**OpenMEPTest** project.

![](docs/img/RevitTestFrameworkGUI.png)

#### Please avoid:

- Lots of unrelated changes in one commit.
Expand Down
1 change: 1 addition & 0 deletions OpenMEP.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt
docs\OpenMEP_DynamoCustomization.xml = docs\OpenMEP_DynamoCustomization.xml
docs\OpenMEPSandbox_DynamoCustomization.xml = docs\OpenMEPSandbox_DynamoCustomization.xml
docs\sandbox\pkg.json = docs\sandbox\pkg.json
CONTRIBUTING.md = CONTRIBUTING.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeployInstaller", "DeployInstaller\DeployInstaller.csproj", "{C7835EFE-E1C7-48B2-90D0-E943D43A905D}"
Expand Down
57 changes: 51 additions & 6 deletions OpenMEP/ConnectorManager/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class Connector
{
private Connector()
{

}

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

return Farthest;
}

/// <summary>
/// Return Farthest Connector between element1 with element2
/// </summary>
Expand All @@ -220,7 +219,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
Autodesk.Revit.DB.Connector? connector = GetConnectorFarthest(element2, connectorSet);
return connector;
}

/// <summary>
/// Get Farthest Connector With Element
/// </summary>
Expand All @@ -245,6 +244,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
}
}
}

return farthest;
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
if (connectorManager == null) throw new ArgumentNullException(nameof(connectorManager));
return GetUnusedConnectors(connectorManager);
}

/// <summary>
/// return list connector used from element
/// </summary>
Expand All @@ -301,7 +301,7 @@ public static double Radius(Autodesk.Revit.DB.Connector connector)
{
if (element == null) throw new ArgumentNullException(nameof(element));
if (GetConnectors(element).Any()) return new List<Autodesk.Revit.DB.Connector?>();
return GetConnectors(element).Where(x=>x!.IsConnected).ToList();
return GetConnectors(element).Where(x => x!.IsConnected).ToList();
}

/// <summary>
Expand Down Expand Up @@ -604,10 +604,11 @@ public static double AssignedKCoefficient(Autodesk.Revit.DB.Connector connector)
if (connector.IsConnected)
{
return connector.AllRefs.Cast<Autodesk.Revit.DB.Connector>()
.Where(x=>x.Owner.Id!=connector.Owner.Id)
.Where(x => x.Owner.Id != connector.Owner.Id)
.Where(x => x.ConnectorType != ConnectorType.Logical)
.Select(x => x.Owner.ToDynamoType()).FirstOrDefault();
}

return null;
}

Expand Down Expand Up @@ -838,4 +839,48 @@ public static Autodesk.Revit.DB.Connector ConnectTo(Autodesk.Revit.DB.Connector
TransactionManager.Instance.TransactionTaskDone();
return connector;
}

/// <summary>
/// Shows scalable lines representing the CoordinateSystem of a Connector.
/// </summary>
/// <param name="connector">Autodesk.Revit.DB.Connector</param>
/// <param name="length">double</param>
/// <returns name="Display">GeometryColor order by x,y,z</returns>
/// <returns name="Origin">Point</returns>
/// <returns name="XAxis">Vector(Red color)</returns>
/// <returns name="YAxis">Vector(Green color)</returns>
/// <returns name="ZAxis">Vector(Blue color)</returns>
/// <returns name="XYPlane">Plane(Red-Green color)</returns>
/// <returns name="YZPlane">Plane(Green-Blue color)</returns>
/// <returns name="ZXPlane">Plane(Blue-Red color)</returns>
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "ZAxis", "XYPlane", "YZPlane", "ZXPlane"})]
public static Dictionary<string, object?> Display(Autodesk.Revit.DB.Connector? connector, double length = 1000)
{
if (length <= 0)
{
length = 1;
}

if (connector == null) return new Dictionary<string, object?>();
var origin = connector.Origin.ToDynamoType();
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
#if R20
DisplayUnitType unitTypeId = doc.GetUnits().GetFormatOptions(UnitType.UT_Length).DisplayUnits;
double xUnits = UnitUtils.ConvertFromInternalUnits(origin.X, unitTypeId);
double yUnits = UnitUtils.ConvertFromInternalUnits(origin.Y, unitTypeId);
double zUnits = UnitUtils.ConvertFromInternalUnits(origin.Z, unitTypeId);
#else
ForgeTypeId unitTypeId = doc.GetUnits().GetFormatOptions(SpecTypeId.Length).GetUnitTypeId();
double xUnits = UnitUtils.ConvertFromInternalUnits(origin.X, unitTypeId);
double yUnits = UnitUtils.ConvertFromInternalUnits(origin.Y, unitTypeId);
double zUnits = UnitUtils.ConvertFromInternalUnits(origin.Z, unitTypeId);
#endif

Point point = Autodesk.DesignScript.Geometry.Point.ByCoordinates(xUnits, yUnits, zUnits);
var X = connector.CoordinateSystem.BasisX.ToDynamoVector();
var Y = connector.CoordinateSystem.BasisY.ToDynamoVector();
var Z = connector.CoordinateSystem.BasisZ.ToDynamoVector();
CoordinateSystem coordinateSystem = Autodesk.DesignScript.Geometry.CoordinateSystem.ByOriginVectors(point, X, Y, Z);
return OpenMEPSandbox.Geometry.CoordinateSystem.Display(coordinateSystem,length);
}
}
2 changes: 1 addition & 1 deletion OpenMEP/ConnectorManager/ConnectorManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static Revit.Elements.Element Owner( Autodesk.Revit.DB.ConnectorManager c
/// </summary>
/// <param name="connectorManager">connector manager</param>
/// <returns name="connectors">a collections of connector manager</returns>
public static List<Autodesk.Revit.DB.Connector> Connectors( Autodesk.Revit.DB.ConnectorManager connectorManager)
public static List<Autodesk.Revit.DB.Connector> Connectors( Autodesk.Revit.DB.ConnectorManager? connectorManager)
{
List<Autodesk.Revit.DB.Connector> connectors = new List<Autodesk.Revit.DB.Connector>();
ConnectorSet connectorSet = connectorManager.Connectors;
Expand Down
1 change: 1 addition & 0 deletions OpenMEP/OpenMEP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynVersion).*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="DynamoVisualProgramming.DynamoCoreNodes" Version="$(DynVersion).*" />
<PackageReference Include="DynamoVisualProgramming.Revit" Version="$(DynVersion).*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
Expand Down
54 changes: 54 additions & 0 deletions OpenMEPSandbox/Geometry/CoordinateSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Autodesk.DesignScript.Runtime;

namespace OpenMEPSandbox.Geometry;

public class CoordinateSystem
{
private CoordinateSystem()
{
}

/// <summary>
/// Shows scalable lines representing the CoordinateSystem axes and rectangles for the planes
/// </summary>
/// <param name="coordinateSystem">Autodesk.DesignScript.Geometry.CoordinateSystem</param>
/// <param name="length">double</param>
/// <returns name="Display">GeometryColor</returns>
/// <returns name="Origin">Point</returns>
/// <returns name="XAxis">Vector</returns>
/// <returns name="YAxis">Vector</returns>
/// <returns name="ZAxis">Vector</returns>
/// <returns name="XYPlane">Plane</returns>
/// <returns name="YZPlane">Plane</returns>
/// <returns name="ZXPlane">Plane</returns>
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "ZAxis", "XYPlane", "YZPlane", "ZXPlane"})]
public static Dictionary<string, object?> Display(Autodesk.DesignScript.Geometry.CoordinateSystem coordinateSystem,
double length = 1000)
{
if (length <= 0)
{
length = 1;
}
var pt = coordinateSystem.Origin;
var lineX = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, coordinateSystem.XAxis, length);
var colorX = DSCore.Color.ByARGB(255, 255, 0, 0);
var lineY = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, coordinateSystem.YAxis, length);
var colorY = DSCore.Color.ByARGB(255, 0, 255, 0);
var lineZ = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, coordinateSystem.ZAxis, length);
var colorZ = DSCore.Color.ByARGB(255, 0, 0, 255);
List<Modifiers.GeometryColor> display = new List<Modifiers.GeometryColor>();
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineX, colorX));
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineY, colorY));
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineZ, colorZ));
var d = new Dictionary<string, object?>();
d.Add("Display", display);
d.Add("Origin", pt);
d.Add("XAxis", coordinateSystem.XAxis);
d.Add("YAxis", coordinateSystem.YAxis);
d.Add("ZAxis", coordinateSystem.ZAxis);
d.Add("XYPlane", coordinateSystem.XYPlane);
d.Add("YZPlane", coordinateSystem.YZPlane);
d.Add("ZXPlane", coordinateSystem.ZXPlane);
return d;
}
}
47 changes: 45 additions & 2 deletions OpenMEPSandbox/Geometry/Plane.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
namespace OpenMEPSandbox.Geometry;
using Autodesk.DesignScript.Geometry;
using Autodesk.DesignScript.Runtime;

namespace OpenMEPSandbox.Geometry;

public class Plane
{
private Plane()
{

}

/// <summary>
/// Shows scalable lines representing the axes and a rectangle for the Plane
/// </summary>
/// <param name="plane">Autodesk.DesignScript.Geometry.Plane</param>
/// <param name="length">double</param>
/// <returns name="Display">GeometryColor</returns>
/// <returns name="Origin">Point</returns>
/// <returns name="XAxis">Vector</returns>
/// <returns name="YAxis">Vector</returns>
/// <returns name="Normal">Vector</returns>
[MultiReturn(new[] {"Display", "Origin", "XAxis", "YAxis", "Normal"})]
public static Dictionary<string, object?> Display(Autodesk.DesignScript.Geometry.Plane? plane, double length = 1000)
{
if (length <= 0)
{
length = 1;
}
if (plane == null) return new Dictionary<string, object?>();
var pt = plane.Origin;
var lineX = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, plane.XAxis, length);
var colorX = DSCore.Color.ByARGB(255, 255, 0, 0);
var lineY = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, plane.YAxis, length);
var colorY = DSCore.Color.ByARGB(255, 0, 255, 0);
var lineN = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(pt, plane.Normal, length);
var colorN = DSCore.Color.ByARGB(255, 0, 0, 255);
var rect = Rectangle.ByWidthLength(plane, length, length);
var colorR = DSCore.Color.ByARGB(50, 50, 50, 50);
List<Modifiers.GeometryColor> display = new List<Modifiers.GeometryColor>();
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineX, colorX));
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineY, colorY));
display.Add(Modifiers.GeometryColor.ByGeometryColor(lineN, colorN));
display.Add(Modifiers.GeometryColor.ByGeometryColor(rect, colorR));
var d = new Dictionary<string, object?>();
d.Add("Display", display);
d.Add("Origin", pt);
d.Add("XAxis", plane.XAxis);
d.Add("YAxis", plane.YAxis);
d.Add("Normal", plane.Normal);
return d;
}
}
34 changes: 33 additions & 1 deletion OpenMEPSandbox/Geometry/Vector.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dynamo.Graph.Nodes;
using Autodesk.DesignScript.Runtime;
using Dynamo.Graph.Nodes;

namespace OpenMEPSandbox.Geometry;

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

/// <summary>
/// Shows a scalable line representing a Vector from a chosen starting point
/// </summary>
/// <param name="vector">Autodesk.DesignScript.Geometry.Vector</param>
/// <param name="startPoint">Autodesk.DesignScript.Geometry.Point</param>
/// <param name="scale">value scale start from 1</param>
/// <returns name="Display">GeometryColor</returns>
/// <returns name="X">double</returns>
/// <returns name="Y">double</returns>
/// <returns name="Z">double</returns>
/// <returns name="Length">double</returns>
[MultiReturn(new[] { "Display", "X", "Y", "Z", "Length" })]
public static Dictionary<string, object?> Display(Autodesk.DesignScript.Geometry.Vector vector, Autodesk.DesignScript.Geometry.Point startPoint, double scale = 1000)
{
if (scale <= 0)
{
scale = 1;
}
var line = Autodesk.DesignScript.Geometry.Line.ByStartPointDirectionLength(startPoint, vector, vector.Length * scale);
var color = DSCore.Color.ByARGB(255, 255, 0, 0);
List<Modifiers.GeometryColor> display = new List<Modifiers.GeometryColor>();
display.Add(Modifiers.GeometryColor.ByGeometryColor(line, color));
var d = new Dictionary<string, object?>();
d.Add("Display", display);
d.Add("X", vector.X);
d.Add("Y", vector.Y);
d.Add("Z", vector.Z);
d.Add("Length", vector.Length);
return d;
}


}
1 change: 1 addition & 0 deletions OpenMEPSandbox/OpenMEPSandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GShark" Version="2.2.0" />
<PackageReference Include="DynamoVisualProgramming.DynamoCoreNodes" Version="$(DynVersion).*" />
<PackageReference Include="DynamoVisualProgramming.Core" Version="$(DynVersion).*">
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
Expand Down
24 changes: 24 additions & 0 deletions OpenMEPTest/Application/DynamoTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using RevitServices.Persistence;

namespace OpenMEPTest.Application;

[TestFixture]
public class DynamoTest
{
[SetUp]
public void SetUp()
{
DocumentManager.Instance.CurrentUIApplication =
RTF.Applications.RevitTestExecutive.CommandData.Application;
DocumentManager.Instance.CurrentUIDocument =
RTF.Applications.RevitTestExecutive.CommandData.Application.ActiveUIDocument;
}

[Test]
public void CanGetDynamoVersion()
{
string version = OpenMEP.Application.Dynamo.Version();
Assert.IsTrue(version.Length > 0);
}
}
24 changes: 24 additions & 0 deletions OpenMEPTest/Application/OpenMEPTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using NUnit.Framework;
using RevitServices.Persistence;

namespace OpenMEPTest.Application;

[TestFixture]
public class OpenMEPTest
{
[SetUp]
public void SetUp()
{
DocumentManager.Instance.CurrentUIApplication =
RTF.Applications.RevitTestExecutive.CommandData.Application;
DocumentManager.Instance.CurrentUIDocument =
RTF.Applications.RevitTestExecutive.CommandData.Application.ActiveUIDocument;
}

[Test]
public void CanGetOpenMEPVersion()
{
string version = OpenMEP.Application.Dynamo.Version();
Assert.IsTrue(version.Length > 0);
}
}
Loading

0 comments on commit 0b38b5d

Please sign in to comment.