Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Mar 2, 2023
2 parents 8bb0b04 + ea4c075 commit dfdd161
Show file tree
Hide file tree
Showing 8 changed files with 421 additions and 350 deletions.
46 changes: 46 additions & 0 deletions OpenMEP/Element/DuctSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Plumbing;
using OpenMEP.Helpers;
using RevitServices.Persistence;

namespace OpenMEP.Element;

public class DuctSystem
{
private DuctSystem()
{
}

/// <summary>
/// flag true to return all ducting systems
/// </summary>
/// <param name="toggle">flag true or false to fresh</param>
/// <returns name="ductSystemTypes">pipePingSystemTypes</returns>
public static IEnumerable<Revit.Elements.Element?> GetAllDuctSystemTypes(bool toggle)
{
// filter for all piping systems
Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
Autodesk.Revit.DB.ElementClassFilter filter = new Autodesk.Revit.DB.ElementClassFilter(typeof(Autodesk.Revit.DB.Mechanical.MechanicalSystemType));
Autodesk.Revit.DB.FilteredElementIterator iterator = collector.WherePasses(filter).GetElementIterator();
iterator.Reset();
while (iterator.MoveNext())
{
Autodesk.Revit.DB.Element element = iterator.Current!;
if (element is MechanicalSystemType pipingSystemType)
{
yield return pipingSystemType.ToDynamoType();
}
}
}

/// <summary>
/// return duct system type by name
/// </summary>
/// <param name="typeName">name of pipe system type</param>
/// <returns name="ductSystemType">the element system type</returns>
public static Revit.Elements.Element? GetDuctSystemTypeByName(string typeName)
{
return GetAllDuctSystemTypes(true).FirstOrDefault(x => x!.Name == typeName);
}

}
48 changes: 48 additions & 0 deletions OpenMEP/Element/DuctType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using OpenMEP.Helpers;
using RevitServices.Persistence;

namespace OpenMEP.Element;

public class DuctType
{
private DuctType()
{

}

/// <summary>
/// get pipe type by name
/// </summary>
/// <param name="typeName">type name of duct</param>
/// <returns name="ductType">type of duct</returns>
public static Revit.Elements.Element? GetDuctTypeByName(string typeName)
{
return GetAllDuctTypes().FirstOrDefault(x => x!.Name == typeName);
}

/// <summary>
/// return all duct types of the current document
/// </summary>
/// <returns name="ductTypes">All Duct Types</returns>
public static List<Revit.Elements.Element?> GetAllDuctTypes()
{
// Get all the pipe types in the current document
Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
Autodesk.Revit.DB.FilteredElementCollector collector = new Autodesk.Revit.DB.FilteredElementCollector(doc);
Autodesk.Revit.DB.ElementClassFilter filter = new Autodesk.Revit.DB.ElementClassFilter(typeof(Autodesk.Revit.DB.Mechanical.DuctType));
Autodesk.Revit.DB.FilteredElementIterator iterator = collector.WherePasses(filter).GetElementIterator();
iterator.Reset();
List<Revit.Elements.Element?> pipeTypes = new List<Revit.Elements.Element?>();
while (iterator.MoveNext())
{
Autodesk.Revit.DB.Element element = iterator.Current!;
if (element is Autodesk.Revit.DB.Mechanical.DuctType ductType)
{
pipeTypes.Add(ductType.ToDynamoType());
}
}
return pipeTypes;
}


}
136 changes: 136 additions & 0 deletions OpenMEP/Element/MEPCurveType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using System.Security.Policy;
using OpenMEP.Helpers;

namespace OpenMEP.Element;

/// <summary>
/// A class can use for DuctType, PipeType, CableTrayType, ConduitType, WireType, MEPCurveType
/// </summary>
public class MEPCurveType
{
private MEPCurveType()
{

}

/// <summary>The default cross fitting of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>This property is used to retrieve the default cross fitting of the MEP curve type,
/// and can be <see langword="null" /> if there is no default value.
/// Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.
/// </remarks>
/// <returns name="familyType">Cross fitting</returns>
public static Revit.Elements.Element? Cross(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
if(mepCurveType!.Cross== null) return null;
return mepCurveType!.Cross.ToDynamoType();
}

/// <summary>The default elbow fitting of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>This property is used to retrieve the default elbow fitting of the MEP curve type,
/// and can be <see langword="null" /> if there is no default value.
/// Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.
/// </remarks>
/// <returns name="familyType">Elbow fitting</returns>
public static Revit.Elements.Element? Elbow(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
if(mepCurveType!.Elbow== null) return null;
return mepCurveType!.Elbow.ToDynamoType();
}

/// <summary>The default tap fitting of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>This property is used to retrieve the default tap fitting of the MEP curve type,
/// and can be <see langword="null" /> if there is no default value.
/// Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.
/// </remarks>
/// <returns name="familyType">Tap fitting</returns>
public static Revit.Elements.Element? Tap(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
if(mepCurveType!.Tap== null) return null;
return mepCurveType!.Tap.ToDynamoType();
}

/// <summary>The default union fitting of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>This property is used to retrieve the default union fitting of the MEP curve type,
/// and can be <see langword="null" /> if there is no default value.
/// Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.
/// </remarks>
/// <returns name="familyType">union fitting</returns>
public static Revit.Elements.Element? Union(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
if(mepCurveType!.Union== null) return null;
return mepCurveType!.Union.ToDynamoType();
}

/// <summary>The default transition fitting of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>This property is used to retrieve the default transition fitting of the MEP curve type,
/// and can be <see langword="null" /> if there is no default value.
/// Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.
/// </remarks>
/// <returns name="familyType">transition fitting</returns>
public static Revit.Elements.Element? Transition(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
if(mepCurveType!.Transition== null) return null;
return mepCurveType!.Transition.ToDynamoType();
}

/// <summary>The default multi shape transition fitting of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>This property is used to retrieve the default multi shape transition fitting of the MEP curve type,
/// and can be <see langword="null" /> if there is no default value.
/// Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.
/// </remarks>
/// <returns name="familyType"> multi shape transition fitting</returns>
public static Revit.Elements.Element? MultiShapeTransition(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
if (mepCurveType!.MultiShapeTransition == null) return null;
return mepCurveType.MultiShapeTransition.ToDynamoType();
}

/// <summary>The shape of the profile.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <since>2019</since>
/// <returns name="Autodesk.Revit.DB.ConnectorProfileType">ConnectorProfileType</returns>
public static dynamic Shape(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
return mepCurveType!.Shape;
}

/// <summary>The roughness of the MEP curve type. For PipeTypes, please use Segment::Roughness</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <returns name="double">Roughness</returns>
public static double Roughness(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
return mepCurveType!.Roughness;
}

/// <summary>The preferred junction type of the MEP curve type.</summary>
/// <para name="mepcurvetype">type of mep curve</para>
/// <remarks>Use <see cref="T:Autodesk.Revit.DB.RoutingPreferenceManager" /> to set this property for PipeType MEPCurves.</remarks>
public static dynamic PreferredJunctionType(Revit.Elements.Element mepcurvetype)
{
if (mepcurvetype == null) throw new ArgumentNullException(nameof(mepcurvetype));
var mepCurveType = mepcurvetype.InternalElement as Autodesk.Revit.DB.MEPCurveType;
return mepCurveType!.PreferredJunctionType;
}
}
10 changes: 5 additions & 5 deletions OpenMEP/Element/Pipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ Autodesk.DesignScript.Geometry.Point point
/// Return Tee Of Pipe In Routing Preferences
/// </summary>
/// <param name="pipe">pipe</param>
/// <returns name="tee">tee</returns>
/// <returns name="familyType">tee</returns>
public static global::Revit.Elements.Element? GetTee(global::Revit.Elements.Element pipe)
{
Autodesk.Revit.DB.Plumbing.Pipe? pipeInternalElement = pipe.InternalElement as Autodesk.Revit.DB.Plumbing.Pipe;
Expand All @@ -536,7 +536,7 @@ Autodesk.DesignScript.Geometry.Point point
/// Return Union Of Pipe In Routing Preferences
/// </summary>
/// <param name="pipe">pipe</param>
/// <returns name="union">union</returns>
/// <returns name="familyType">union</returns>
public static global::Revit.Elements.Element? GetUnion(global::Revit.Elements.Element pipe)
{
Autodesk.Revit.DB.Plumbing.Pipe? pipeInternalElement = pipe.InternalElement as Autodesk.Revit.DB.Plumbing.Pipe;
Expand All @@ -549,7 +549,7 @@ Autodesk.DesignScript.Geometry.Point point
/// Return Cross Of Pipe In Routing Preferences
/// </summary>
/// <param name="pipe">pipe</param>
/// <returns name="cross">cross</returns>
/// <returns name="familyType">cross</returns>
public static global::Revit.Elements.Element? GetCross(global::Revit.Elements.Element pipe)
{
Autodesk.Revit.DB.Plumbing.Pipe? pipeInternalElement = pipe.InternalElement as Autodesk.Revit.DB.Plumbing.Pipe;
Expand All @@ -562,7 +562,7 @@ Autodesk.DesignScript.Geometry.Point point
/// Return Tap Of Pipe In Routing Preferences
/// </summary>
/// <param name="pipe">pipe</param>
/// <returns name="tap">tap</returns>
/// <returns name="familyType">tap</returns>
public static global::Revit.Elements.Element? GetTap(global::Revit.Elements.Element pipe)
{
Autodesk.Revit.DB.Plumbing.Pipe? pipeInternalElement = pipe.InternalElement as Autodesk.Revit.DB.Plumbing.Pipe;
Expand All @@ -576,7 +576,7 @@ Autodesk.DesignScript.Geometry.Point point
/// Return Transition Of Pipe In Routing Preferences
/// </summary>
/// <param name="pipe">pipe</param>
/// <returns name="transition">transition</returns>
/// <returns name="familyType">transition</returns>
public static global::Revit.Elements.Element? GetTransition(global::Revit.Elements.Element pipe)
{
Autodesk.Revit.DB.Plumbing.Pipe? pipeInternalElement = pipe.InternalElement as Autodesk.Revit.DB.Plumbing.Pipe;
Expand Down
12 changes: 11 additions & 1 deletion OpenMEP/Element/PipingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private PipingSystem()
/// flag true to return all piping systems
/// </summary>
/// <param name="toggle">flag true or false to fresh</param>
/// <returns name="pipeingSystemTypes">pipePingSystemTypes</returns>
/// <returns name="pipeSystemTypes">pipeSystemTypes</returns>
public static IEnumerable<Revit.Elements.Element?> GetAllPipeSystemTypes(bool toggle)
{
// filter for all piping systems
Expand All @@ -33,4 +33,14 @@ private PipingSystem()
}
}

/// <summary>
/// return pipe system type by name
/// </summary>
/// <param name="typeName">name of pipe system type</param>
/// <returns name="pipeSystemType">the element system type</returns>
public static Revit.Elements.Element? GetPipeSystemTypeByName(string typeName)
{
return GetAllPipeSystemTypes(true).FirstOrDefault(x => x!.Name == typeName);
}

}
16 changes: 6 additions & 10 deletions OpenMEPSandbox/Geometry/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,16 @@ private Point()
/// Project a point onto a plane
/// </summary>
/// <param name="point">point need to project</param>
/// <param name="planeNormal">vector normal of plane</param>
/// <param name="plane">plane to be project</param>
/// <returns name="point">new point projected on plane</returns>
public static Autodesk.DesignScript.Geometry.Point ProjectOntoPlane(
Autodesk.DesignScript.Geometry.Point point,
Autodesk.DesignScript.Geometry.Vector planeNormal)
Autodesk.DesignScript.Geometry.Plane plane)
{
double a = planeNormal.X;
double b = planeNormal.Y;
double c = planeNormal.Z;

double dx = (b * b + c * c) * point.X - (a * b) * point.Y - (a * c) * point.Z;
double dy = -(b * a) * point.X + (a * a + c * c) * point.Y - (b * c) * point.Z;
double dz = -(c * a) * point.X - (c * b) * point.Y + (a * a + b * b) * point.Z;
return Autodesk.DesignScript.Geometry.Point.ByCoordinates(dx, dy, dz);
Point3 point3 = point.ToGSharkType();
GShark.Geometry.Plane plane1 = plane.ToGSharkType();
Point3 projectedPoint = point3.ProjectToPlan(plane1);
return Autodesk.DesignScript.Geometry.Point.ByCoordinates(projectedPoint.X, projectedPoint.Y, projectedPoint.Z);
}

/// <summary>
Expand Down
Loading

0 comments on commit dfdd161

Please sign in to comment.