MepSystemTypeExtension.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using Autodesk.Revit.DB;
  2. using Autodesk.Revit.DB.Mechanical;
  3. using Autodesk.Revit.DB.Plumbing;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace FWindSoft.Revit
  11. {
  12. public static class MepSystemTypeExtension
  13. {
  14. public static readonly ReadOnlyCollection<string> DuctClassifications =new ReadOnlyCollection<string>( new List<string> { "SupplyAir", "ReturnAir", "ExhaustAir" });
  15. public static readonly ReadOnlyCollection<string> PipeClassifications = new ReadOnlyCollection<string>(new List<string> { "Sanitary",
  16. "Vent",
  17. "DomesticHotWater",
  18. "DomesticColdWater",
  19. "OtherPipe",
  20. "FireProtectWet",
  21. "FireProtectDry",
  22. "FireProtectPreaction",
  23. "FireProtectOther",
  24. "SupplyHydronic",
  25. "ReturnHydronic"});
  26. /// <summary>
  27. /// 根据系统分类创建系统类型
  28. /// </summary>
  29. /// <param name="doc">创建系统的指定项目</param>
  30. /// <param name="classification">系统分类</param>
  31. /// <param name="name">系统名称</param>
  32. /// <returns></returns>
  33. public static MEPSystemType MEPSystemTypeCreate(this Document doc, MEPSystemClassification classification,string name)
  34. {
  35. if (DuctClassifications.Contains(classification.ToString()))
  36. return MechanicalSystemType.Create(doc, classification, name);
  37. if (PipeClassifications.Contains(classification.ToString()))
  38. return PipingSystemType.Create(doc, classification, name);
  39. return null;
  40. }
  41. /// <summary>
  42. /// 或取全部管道系统(可指定相应的系统分类)
  43. /// </summary>
  44. /// <param name="doc"></param>
  45. /// <param name="classification"></param>
  46. /// <returns></returns>
  47. public static List<PipingSystemType> GetPipingSystemTypes(this Document doc,
  48. MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification)
  49. {
  50. ElementCategoryFilter pipeSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipingSystem);
  51. List<PipingSystemType> list = doc.GetElements<PipingSystemType>();
  52. if (classification != MEPSystemClassification.UndefinedSystemClassification)
  53. {
  54. list = list.Where(s => s.SystemClassification == classification).ToList();
  55. }
  56. return list;
  57. }
  58. /// <summary>
  59. /// 或取项目已经使用的管道系统(可指定相应的系统分类)
  60. /// </summary>
  61. /// <param name="doc"></param>
  62. /// <param name="classification"></param>
  63. /// <returns></returns>
  64. public static List<PipingSystemType> GetUsedPipingSystemTypes(this Document doc,
  65. MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification)
  66. {
  67. ElementCategoryFilter pipeSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipingSystem);
  68. var listIds = doc.GetElements<PipingSystem>().Select(p => p.GetTypeId()).Distinct();
  69. List<Element> list = listIds.Select(id => doc.GetElement(id)).ToList();
  70. List<PipingSystemType> tempSystemType = list.OfType<PipingSystemType>().ToList();
  71. if (classification != MEPSystemClassification.UndefinedSystemClassification)
  72. {
  73. tempSystemType = tempSystemType.Where(s => s.SystemClassification == classification).ToList();
  74. }
  75. return tempSystemType;
  76. }
  77. /// <summary>
  78. /// 或取全部风管系统类型(可指定相应的系统分类)
  79. /// </summary>
  80. /// <param name="doc"></param>
  81. /// <param name="classification"></param>
  82. /// <returns></returns>
  83. public static List<MechanicalSystemType> GetMechanicalSystemTypes(this Document doc,
  84. MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification)
  85. {
  86. ElementCategoryFilter ductSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_DuctSystem);
  87. List<MechanicalSystemType> list = doc.GetElements(ductSystemFilter).OfType<MechanicalSystemType>().ToList();
  88. if (classification != MEPSystemClassification.UndefinedSystemClassification)
  89. {
  90. list = list.Where(s => s.SystemClassification == classification).ToList();
  91. }
  92. return list;
  93. }
  94. /// <summary>
  95. /// 或取项目已经使用的风管系统系统(可指定相应的系统分类)
  96. /// </summary>
  97. /// <param name="doc"></param>
  98. /// <param name="classification"></param>
  99. /// <returns></returns>
  100. public static List<MechanicalSystemType> GetUsedMechanicalSystemTypes(this Document doc,
  101. MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification)
  102. {
  103. ElementCategoryFilter ductSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_DuctSystem);
  104. var listIds = doc.GetElements(ductSystemFilter).OfType<MechanicalSystemType>()
  105. .Select(p => p.GetTypeId())
  106. .Distinct();
  107. List<Element> list = listIds.Select(id => doc.GetElement(id)).ToList();
  108. List<MechanicalSystemType> tempSystemType = list.OfType<MechanicalSystemType>().ToList();
  109. if (classification != MEPSystemClassification.UndefinedSystemClassification)
  110. {
  111. tempSystemType = tempSystemType.Where(s => s.SystemClassification == classification).ToList();
  112. }
  113. return tempSystemType;
  114. }
  115. }
  116. }