FittingUtils.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Autodesk.Revit.DB;
  2. using Autodesk.Revit.DB.Electrical;
  3. using Autodesk.Revit.DB.Mechanical;
  4. using Autodesk.Revit.DB.Plumbing;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace FWindSoft.Revit.Utils
  11. {
  12. /// <summary>
  13. /// 管件类型枚举
  14. /// </summary>
  15. public enum FittingType
  16. {
  17. /// <summary>
  18. /// 未定
  19. /// </summary>
  20. Undefined = -1,
  21. /// <summary>
  22. /// 弯头
  23. /// </summary>
  24. Elbows = 1,
  25. /// <summary>
  26. /// 三通
  27. /// </summary>
  28. Junctions = 2,
  29. /// <summary>
  30. /// 四通
  31. /// </summary>
  32. Crosses = 3,
  33. /// <summary>
  34. /// 变径
  35. /// </summary>
  36. Transitions = 4,
  37. /// <summary>
  38. /// 活接头
  39. /// </summary>
  40. Unions = 5,
  41. /// <summary>
  42. /// 方形到原型变径
  43. /// </summary>
  44. TransitionsRectangularToRound = 7,
  45. /// <summary>
  46. /// 方形到椭圆变径
  47. /// </summary>
  48. TransitionsRectangularToOval = 8,
  49. /// <summary>
  50. /// 椭圆到原型变径
  51. /// </summary>
  52. TransitionsOvalToRound = 9,
  53. /// <summary>
  54. /// 堵头
  55. /// </summary>
  56. Caps = 10
  57. }
  58. /// <summary>
  59. /// 管件工具
  60. /// </summary>
  61. public static class FittingUtils
  62. {
  63. #region 私有方法
  64. /// <summary>
  65. /// 判断传入类型的的分类
  66. /// </summary>
  67. /// <param name="mepCurveType"></param>
  68. /// <returns>-1 无效;0 线管桥架;1水管风管 </returns>
  69. private static int JudgeType(MEPCurveType mepCurveType)
  70. {
  71. int flag = -1;
  72. if (mepCurveType is ConduitType || mepCurveType is CableTrayType)
  73. {
  74. return 0;
  75. }
  76. if (mepCurveType is PipeType || mepCurveType is DuctType)
  77. {
  78. return 1;
  79. }
  80. return flag;
  81. }
  82. /// <summary>
  83. /// FittingType转换成布线规则
  84. /// </summary>
  85. /// <param name="fittingType"></param>
  86. /// <returns></returns>
  87. private static RoutingPreferenceRuleGroupType ConvertToRuleType(FittingType fittingType)
  88. {
  89. return (RoutingPreferenceRuleGroupType)fittingType;
  90. }
  91. /// <summary>
  92. /// FittingType转换成对应参数
  93. /// </summary>
  94. /// <param name="fittingType"></param>
  95. /// <returns></returns>
  96. private static BuiltInParameter ConvertToBitParameter(FittingType fittingType)
  97. {
  98. BuiltInParameter use = BuiltInParameter.INVALID;
  99. switch (fittingType)
  100. {
  101. case FittingType.Elbows:
  102. use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_BEND_PARAM;
  103. break;
  104. case FittingType.Junctions:
  105. use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_TEE_PARAM;
  106. break;
  107. case FittingType.Crosses:
  108. use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_CROSS_PARAM;
  109. break;
  110. case FittingType.Transitions:
  111. use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_TRANSITION_PARAM;
  112. break;
  113. case FittingType.Unions:
  114. use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_UNION_PARAM;
  115. break;
  116. case FittingType.Caps:
  117. use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_CAP_PARAM;
  118. break;
  119. default:
  120. break;
  121. }
  122. return use;
  123. }
  124. #endregion
  125. /// <summary>
  126. /// MepCurveType增加指定类型的管件
  127. /// </summary>
  128. /// <param name="mepCurveType"></param>
  129. /// <param name="fittingType">管件类型</param>
  130. /// <param name="elementId"></param>
  131. public static void AddFitting(MEPCurveType mepCurveType, FittingType fittingType, ElementId elementId)
  132. {
  133. var flag = JudgeType(mepCurveType);
  134. elementId = elementId??ElementId.InvalidElementId;
  135. if (flag==0)
  136. {
  137. mepCurveType.AddFitting(ConvertToBitParameter(fittingType), elementId);
  138. }
  139. else if(flag==1)
  140. {
  141. mepCurveType.AddRoutingRule(ConvertToRuleType(fittingType), elementId);
  142. }
  143. }
  144. /// <summary>
  145. /// MepCurveType移除指定管件
  146. /// </summary>
  147. /// <param name="mepCurveType"></param>
  148. /// <param name="fittingType"></param>
  149. public static void RemoveFitting(MEPCurveType mepCurveType, FittingType fittingType)
  150. {
  151. var flag = JudgeType(mepCurveType);
  152. if (flag == 0)
  153. {
  154. mepCurveType.RemoveFitting(ConvertToBitParameter(fittingType));
  155. }
  156. else if (flag == 1)
  157. {
  158. mepCurveType.RemoveRoutingRule(ConvertToRuleType(fittingType));
  159. }
  160. }
  161. /// <summary>
  162. /// MepCurveType获取指定管件
  163. /// </summary>
  164. /// <param name="mepCurveType"></param>
  165. /// <param name="fittingType"></param>
  166. /// <returns></returns>
  167. public static ElementId GetFitting(MEPCurveType mepCurveType, FittingType fittingType)
  168. {
  169. ElementId elmentId = null;
  170. var flag = JudgeType(mepCurveType);
  171. if (flag == 0)
  172. {
  173. elmentId=mepCurveType.GetFitting(ConvertToBitParameter(fittingType));
  174. }
  175. else if (flag == 1)
  176. {
  177. var rule = mepCurveType.GetRoutingRule(ConvertToRuleType(fittingType));
  178. if(rule!=null)
  179. {
  180. elmentId = rule.MEPPartId;
  181. }
  182. }
  183. return elmentId;
  184. }
  185. }
  186. }