SpaceExtend.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* ==============================================================================
  2. * 功能描述:SpaceExtend
  3. * 创 建 者:Garrett
  4. * 创建日期:2017/11/21 11:55:16
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Autodesk.Revit.DB;
  12. using Autodesk.Revit.DB.Mechanical;
  13. namespace SAGA.RevitUtils.Extends
  14. {
  15. /// <summary>
  16. /// SpaceExtend
  17. /// </summary>
  18. public static class SpaceExtend
  19. {
  20. /// <summary>
  21. /// 获取空间在平面上的范围的点集合
  22. /// </summary>
  23. /// <param name="space"></param>
  24. /// <returns></returns>
  25. public static List<XYZ> GetPlaneVertexes(this Space space)
  26. {
  27. List<XYZ> xyzs = new List<XYZ>();
  28. var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
  29. if (segments != null)
  30. {
  31. foreach (IList<Autodesk.Revit.DB.BoundarySegment> segmentList in segments)
  32. {
  33. foreach (Autodesk.Revit.DB.BoundarySegment boundarySegment in segmentList)
  34. {
  35. //此处可能需要排序
  36. var startXyz = boundarySegment.GetCurve().GetEndPoint(0);
  37. var endXyz = boundarySegment.GetCurve().GetEndPoint(1);
  38. if (!xyzs.Contains(startXyz, new XyzEqualComparer()))
  39. xyzs.Add(startXyz);
  40. if (!xyzs.Contains(endXyz, new XyzEqualComparer()))
  41. xyzs.Add(endXyz);
  42. }
  43. }
  44. }
  45. return xyzs;
  46. }
  47. public static List<XYZ> GetPlaneOutVertexes(this Space space)
  48. {
  49. List<XYZ> xyzs = new List<XYZ>();
  50. var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
  51. if (segments != null)
  52. {
  53. foreach (IList<BoundarySegment> segmentList in segments)
  54. {
  55. foreach (BoundarySegment boundarySegment in segmentList)
  56. {
  57. //此处可能需要排序
  58. //var startXyz = boundarySegment.GetCurve().GetEndPoint(0);
  59. //var endXyz = boundarySegment.GetCurve().GetEndPoint(1);
  60. //if (!xyzs.Contains(startXyz, new XyzEqualComparer()))
  61. // xyzs.Add(startXyz);
  62. //if (!xyzs.Contains(endXyz, new XyzEqualComparer()))
  63. // xyzs.Add(endXyz);
  64. var inputPoints = boundarySegment.GetCurve().GetPoints();
  65. foreach (var inputPoint in inputPoints)
  66. {
  67. if (!xyzs.Contains(inputPoint, new XyzEqualComparer()))
  68. xyzs.Add(inputPoint);
  69. }
  70. }
  71. break;
  72. }
  73. }
  74. return xyzs;
  75. }
  76. /// <summary>
  77. /// 获取轮廓顶点
  78. /// </summary>
  79. /// <param name="sgements"></param>
  80. /// <returns></returns>
  81. public static List<XYZ> GetBoundaryVertexes(this IList<BoundarySegment> sgements)
  82. {
  83. List<XYZ> xyzs = new List<XYZ>();
  84. foreach (BoundarySegment boundarySegment in sgements)
  85. {
  86. var inputPoints = boundarySegment.GetCurve().GetPoints();
  87. foreach (var inputPoint in inputPoints)
  88. {
  89. if (!xyzs.Contains(inputPoint, new XyzEqualComparer()))
  90. xyzs.Add(inputPoint);
  91. }
  92. }
  93. return xyzs;
  94. }
  95. /// <summary>
  96. /// 获取轮廓相关path
  97. /// </summary>
  98. /// <param name="space"></param>
  99. /// <returns></returns>
  100. public static List<List<XYZ>> GetBoundaryVertexes(this Space space)
  101. {
  102. List<List<XYZ>> paths = new List<List<XYZ>>();
  103. var segments = space.GetBoundarySegments(new SpatialElementBoundaryOptions());
  104. if (segments != null)
  105. {
  106. foreach (IList<BoundarySegment> segmentList in segments)
  107. {
  108. paths.Add(segmentList.GetBoundaryVertexes());
  109. }
  110. }
  111. return paths;
  112. }
  113. /// <summary>
  114. /// 获取所有的Space
  115. /// </summary>
  116. /// <param name="doc"></param>
  117. /// <param name="bic"></param>
  118. /// <returns></returns>
  119. public static List<Space> GetSpaces(this Document doc)
  120. {
  121. return doc.GetElements(typeof(SpatialElement)).Where(t=>t is Space).Cast<Space>().ToList();
  122. }
  123. /// <summary>
  124. /// 空间底部标高
  125. /// </summary>
  126. /// <param name="wall"></param>
  127. /// <returns></returns>
  128. public static Level GetBaseLevel(this Space space)
  129. {
  130. return space.GetParameterElement(BuiltInParameter.ROOM_LEVEL_ID) as Level;
  131. }
  132. /// <summary>
  133. /// 空间底部偏移
  134. /// </summary>
  135. /// <returns></returns>
  136. public static double GetBaseOffSet(this Space space)
  137. {
  138. return space.GetParameterDouble(BuiltInParameter.ROOM_LOWER_OFFSET);
  139. }
  140. /// <summary>
  141. /// 获取底部高度
  142. /// </summary>
  143. /// <param name="space"></param>
  144. /// <returns></returns>
  145. public static double GetBaseStaticHeight(this Space space)
  146. {
  147. return space.GetBaseLevel().Elevation + space.GetBaseOffSet();
  148. }
  149. /// <summary>
  150. /// 空间顶部标高
  151. /// </summary>
  152. /// <param name="space"></param>
  153. /// <returns></returns>
  154. public static Level GetTopLevel(this Space space)
  155. {
  156. return space.GetParameterElement(BuiltInParameter.ROOM_UPPER_LEVEL) as Level;
  157. }
  158. /// <summary>
  159. /// 空间顶部偏移
  160. /// </summary>
  161. /// <param name="space"></param>
  162. /// <returns></returns>
  163. public static double GetTopOffSet(this Space space)
  164. {
  165. return space.GetParameterDouble(BuiltInParameter.ROOM_UPPER_OFFSET);
  166. }
  167. /// <summary>
  168. /// 获取顶部高度
  169. /// </summary>
  170. /// <param name="space"></param>
  171. /// <returns></returns>
  172. public static double GetTopStaticHeight(this Space space)
  173. {
  174. return space.GetTopLevel().Elevation + space.GetTopOffSet();
  175. }
  176. }
  177. }