MepCurveTypeExtension.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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
  11. {
  12. public static class MepCurveTypeExtension
  13. {
  14. #region 水管风管类型布线规则维护
  15. /// <summary>
  16. /// 增加MepCurve优先规则
  17. /// </summary>
  18. /// <param name="pipeDuctType">MepCurve类型</param>
  19. /// <param name="groupType">规则分组</param>
  20. /// <param name="elementId">规则使用的element</param>
  21. /// <param name="index">规则在分组中的位置</param>
  22. /// <returns>-1操作类型不符</returns>
  23. public static int AddRoutingRule(this MEPCurveType pipeDuctType, RoutingPreferenceRuleGroupType groupType,
  24. ElementId elementId, int index = 0)
  25. {
  26. if (pipeDuctType is PipeType || pipeDuctType is DuctType)
  27. {
  28. RoutingPreferenceManager manager = pipeDuctType.RoutingPreferenceManager;
  29. if (null != manager)
  30. {
  31. RoutingPreferenceRule rule = new RoutingPreferenceRule(elementId, "");
  32. rule.AddCriterion(PrimarySizeCriterion.All());
  33. manager.AddRule(groupType, rule, 0);
  34. }
  35. return index;
  36. }
  37. else
  38. {
  39. return -1;
  40. }
  41. }
  42. /// <summary>
  43. /// 移除MepCurve规则分组中制定位置的规则
  44. /// </summary>
  45. /// <param name="pipeDuctType">MepCurve类型</param>
  46. /// <param name="groupType">规则分组</param>
  47. /// <param name="index">规则在该分组中的位置</param>
  48. /// <returns>-1操作类型不符</returns>
  49. public static int RemoveRoutingRule(this MEPCurveType pipeDuctType, RoutingPreferenceRuleGroupType groupType,
  50. int index = 0)
  51. {
  52. if (pipeDuctType is PipeType || pipeDuctType is DuctType)
  53. {
  54. RoutingPreferenceManager manager = pipeDuctType.RoutingPreferenceManager;
  55. if (null != manager)
  56. {
  57. manager.RemoveRule(groupType, index);
  58. }
  59. }
  60. else
  61. {
  62. index = -1;
  63. }
  64. return index;
  65. }
  66. /// <summary>
  67. /// 获取MepCurve优先规则分组中指定位置的规则
  68. /// </summary>
  69. /// <param name="pipeDuctType"></param>
  70. /// <param name="groupType"></param>
  71. /// <param name="index"></param>
  72. /// <returns></returns>
  73. public static RoutingPreferenceRule GetRoutingRule(this MEPCurveType pipeDuctType,
  74. RoutingPreferenceRuleGroupType groupType, int index = 0)
  75. {
  76. RoutingPreferenceManager manager = pipeDuctType.RoutingPreferenceManager;
  77. RoutingPreferenceRule rule = null;
  78. if (pipeDuctType is PipeType || pipeDuctType is DuctType)
  79. {
  80. if (null != manager)
  81. {
  82. rule = manager.GetRule(groupType, index);
  83. }
  84. }
  85. return rule;
  86. }
  87. #endregion
  88. #region 线管桥架连接件类型维护
  89. /// <summary>
  90. /// 修改桥架线管指定连接件的参数
  91. /// </summary>
  92. /// <param name="cableTrayConduitType">桥架线管</param>
  93. /// <param name="parameter">连接件类型参数</param>
  94. /// <param name="elementId">规则使用的element</param>
  95. /// <returns></returns>
  96. public static void AddFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter,ElementId elementId)
  97. {
  98. if(cableTrayConduitType is ConduitType|| cableTrayConduitType is CableTrayType)
  99. {
  100. if (null != cableTrayConduitType)
  101. {
  102. cableTrayConduitType.SetParameter(parameter, elementId);
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 移除桥架线管指定连接件的参数
  108. /// </summary>
  109. /// <param name="cableTrayConduitType">桥架线管</param>
  110. /// <param name="parameter">连接件类型参数</param>
  111. /// <returns></returns>
  112. public static void RemoveFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter)
  113. {
  114. if (cableTrayConduitType is ConduitType || cableTrayConduitType is CableTrayType)
  115. {
  116. if (null != cableTrayConduitType)
  117. {
  118. cableTrayConduitType.SetParameter(parameter, ElementId.InvalidElementId);
  119. }
  120. }
  121. }
  122. /// <summary>
  123. /// 获取桥架线管指定连接件的参数
  124. /// </summary>
  125. /// <param name="cableTrayConduitType"></param>
  126. /// <param name="parameter"></param>
  127. /// <returns></returns>
  128. public static ElementId GetFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter)
  129. {
  130. ElementId elmentId = null;
  131. if (cableTrayConduitType is ConduitType || cableTrayConduitType is CableTrayType)
  132. {
  133. if (null != cableTrayConduitType)
  134. {
  135. elmentId = cableTrayConduitType.GetParameterElementId(parameter);
  136. }
  137. }
  138. return elmentId;
  139. }
  140. #endregion
  141. }
  142. }