InsulationExtension.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using Autodesk.Revit.DB;
  2. using Autodesk.Revit.DB.Mechanical;
  3. using Autodesk.Revit.DB.Plumbing;
  4. using FWindSoft.SystemExtensions;
  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.Extension
  11. {
  12. public static class InsulationExtension
  13. { /// <summary>
  14. /// 获取水管和风管保温层
  15. /// </summary>
  16. /// <param name="doc"></param>
  17. /// <returns></returns>
  18. public static List<ElementType> GetInsulationTypes(this Document doc)
  19. {
  20. ElementFilter pipe = new ElementCategoryFilter(BuiltInCategory.OST_PipeInsulations);
  21. ElementFilter duct = new ElementCategoryFilter(BuiltInCategory.OST_DuctInsulations);
  22. LogicalOrFilter filter = new LogicalOrFilter(pipe, duct);
  23. List<ElementType> types = doc.GetElementTypes<ElementType>(filter);
  24. return types;
  25. }
  26. /// <summary>
  27. /// 获取水管的保温层
  28. /// </summary>
  29. /// <param name="doc"></param>
  30. /// <returns></returns>
  31. public static List<ElementType> GetPipeInsulationTypes(this Document doc)
  32. {
  33. List<ElementType> types = doc.GetElementTypes<ElementType>(new ElementCategoryFilter(BuiltInCategory.OST_PipeInsulations));
  34. return types;
  35. }
  36. /// <summary>
  37. /// 获取风管的保温层
  38. /// </summary>
  39. /// <param name="doc"></param>
  40. /// <returns></returns>
  41. public static List<ElementType> GetDuctInsulationTypes(this Document doc)
  42. {
  43. List<ElementType> types = doc.GetElementTypes<ElementType>(new ElementCategoryFilter(BuiltInCategory.OST_DuctInsulations));
  44. return types;
  45. }
  46. /// <summary>
  47. /// 获取管道和管道连接件的保温层
  48. /// </summary>
  49. /// <param name="doc"></param>
  50. /// <returns></returns>
  51. public static List<InsulationLiningBase> GetPipeInsulations(this Document doc)
  52. {
  53. List<InsulationLiningBase> elements =
  54. doc.GetElements<InsulationLiningBase>().Where(
  55. el =>
  56. el.GetBuiltInCategory() == BuiltInCategory.OST_PipeInsulations ||
  57. el.GetBuiltInCategory() == BuiltInCategory.OST_PipeFittingInsulation).ToList();
  58. return elements.Where(e => e.IsValidObject).ToList();
  59. }
  60. /// <summary>
  61. /// 创建保温层
  62. /// </summary>
  63. /// <param name="element"></param>
  64. /// <param name="info"></param>
  65. public static void CreateInsulation(this Element element, InsulationItem info)
  66. {
  67. if (!element.IsValidObject) return;
  68. if (info == null || info.InsulationType == null) return;
  69. Document doc = element.Document;
  70. if (element.IsWaterComponment())
  71. {
  72. var ids = InsulationLiningBase.GetInsulationIds(doc, element.Id);
  73. doc.Delete(ids);
  74. PipeInsulation.Create(doc, element.Id, info.InsulationType.Id, info.Thickness);
  75. }
  76. else if (element.IsHavcComponment())
  77. {
  78. var ids = InsulationLiningBase.GetInsulationIds(doc, element.Id);
  79. doc.Delete(ids);
  80. DuctInsulation.Create(doc, element.Id, info.InsulationType.Id, info.Thickness);
  81. }
  82. }
  83. /// <summary>
  84. /// 删除保温层
  85. /// </summary>
  86. /// <param name="elements"></param>
  87. public static void DeleteInsulations(this List<Element> elements)
  88. {
  89. var list = elements;
  90. if (list == null || list.Count == 0) return;
  91. Document doc = elements[0].Document;
  92. for (int i = 0; i < list.Count; i++)
  93. {
  94. Element temp = list[i];
  95. if (!temp.IsValidObject) continue;
  96. bool isValid = temp.IsWaterComponment() || temp.IsHavcComponment();
  97. if (!isValid) continue;
  98. var ids = InsulationLiningBase.GetInsulationIds(doc, temp.Id);
  99. doc.Delete(ids);
  100. }
  101. }
  102. /// <summary>
  103. /// 获取指定管道集合中的第一个保温层信息
  104. /// </summary>
  105. /// <param name="elements">elements尽可能只包含水系统或者风系统</param>
  106. /// <returns></returns>
  107. public static InsulationItem GetInsulationItem(this List<Element> elements)
  108. {
  109. InsulationItem info = null;
  110. List<ElementType> pipeInsulation = null;
  111. List<ElementType> ductInsulation = null;
  112. do
  113. {
  114. if (elements == null || elements.Count == 0)
  115. {
  116. break;
  117. }
  118. Document doc = elements[0].Document;
  119. foreach (var element in elements)
  120. {
  121. if (element == null) continue;
  122. string name = element.GetParameterString(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE);
  123. double thick = element.GetParameterDouble(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS);
  124. if (!string.IsNullOrWhiteSpace(name) && thick.More(0))
  125. {
  126. ElementType tempType = null;
  127. if (element.IsWaterComponment())
  128. {
  129. if (pipeInsulation == null)
  130. {
  131. pipeInsulation = doc.GetPipeInsulationTypes();
  132. }
  133. tempType = pipeInsulation.FirstOrDefault(t => t.Name.Equals(name));
  134. }
  135. else if (element.IsHavcComponment())
  136. {
  137. if (ductInsulation == null)
  138. {
  139. ductInsulation = doc.GetDuctInsulationTypes();
  140. }
  141. tempType = ductInsulation.FirstOrDefault(t => t.Name.Equals(name));
  142. }
  143. if (null != tempType)
  144. {
  145. info = new InsulationItem { InsulationType = tempType, Thickness = thick };
  146. break;
  147. }
  148. }
  149. }
  150. } while (false);
  151. return info;
  152. }
  153. }
  154. /// <summary>
  155. /// 保温层包装类
  156. /// </summary>
  157. public class InsulationItem
  158. {
  159. public ElementType InsulationType { get; set; }
  160. public double Thickness { get; set; }
  161. }
  162. }