ElementExtension.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* ==============================================================================
  2. * 功能描述:ElementExtension
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/25 11:51:43
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.DB;
  13. using Autodesk.Revit.DB.Mechanical;
  14. using RevitToJBim.Common;
  15. using RevitToJBim.MBI;
  16. using SAGA.RevitUtils.Extends;
  17. namespace RevitToJBim.Extension
  18. {
  19. /// <summary>
  20. /// ElementExtension
  21. /// </summary>
  22. public static class ElementExtension
  23. {
  24. public static string GetFamilyName(this Element element)
  25. {
  26. return element.GetFamily()?.Name;
  27. }
  28. /// <summary>
  29. /// 获取设备的种族类型编码 ATFC
  30. /// 族名称的命名规则:ATFC-风机盘管
  31. /// </summary>
  32. /// <returns></returns>
  33. public static string GetFamilyCode(this Element element)
  34. {
  35. string code = "";
  36. if (element is FamilyInstance fi)
  37. {
  38. string familyName = fi.GetFamilyName();
  39. if (familyName == null) return code;
  40. //族名称的命名规则:ATFC-风机盘管
  41. int index = familyName.IndexOf('-');
  42. if (index != -1 && index + 1 != familyName.Length)
  43. code = familyName.Substring(0, familyName.IndexOf('-'));
  44. //移除前面和后面的空格
  45. code = code.Trim();
  46. }
  47. return code;
  48. }
  49. /// <summary>
  50. /// 判断是否为设备 设备族为4位
  51. /// ATVR - 多联机 - 室内机 - 双向气流 - 天花板嵌入式
  52. /// </summary>
  53. /// <param name="fi"></param>
  54. /// <returns></returns>
  55. public static bool IsEquipment(this Element element)
  56. {
  57. bool result = false;
  58. if (element is FamilyInstance fi)
  59. {
  60. var family = fi.GetFamilyName();
  61. result = Regex.IsMatch(family, $"{MBIRegexPattern.IsEquip}");
  62. }
  63. return result;
  64. }
  65. /// <summary>
  66. /// 判断是否为设备部件 设备族为6位
  67. /// </summary>
  68. /// <param name="fi"></param>
  69. /// <returns></returns>
  70. public static bool IsEquipmentPart(this Element element)
  71. {
  72. bool result = false;
  73. if (element is FamilyInstance fi)
  74. {
  75. var family = fi.GetFamilyName();
  76. result = Regex.IsMatch(family, $"{MBIRegexPattern.IsEquipPart}");
  77. }
  78. return result;
  79. }
  80. /// <summary>
  81. /// 判断是否为信标
  82. /// </summary>
  83. /// <param name="elem"></param>
  84. /// <returns></returns>
  85. public static bool IsBeacon(this Element elem)
  86. {
  87. var family = elem.GetFamilyName();
  88. return family != null && (Regex.IsMatch(family, MBIRegexPattern.IsBeacon));
  89. }
  90. /// <summary>
  91. /// 判断是否为空间,判断周长是否为零
  92. /// 如果周长为零,是删除的空间
  93. /// </summary>
  94. /// <param name="elem"></param>
  95. /// <param name="ischeckzero">是否检查周长为零</param>
  96. /// <returns></returns>
  97. public static bool IsSpace(this Element elem, bool ischeckzero = true)
  98. {
  99. var isspace = false;
  100. if (elem is Space space)
  101. {
  102. //空间比较特殊,周长为零就相当于删除
  103. isspace = !ischeckzero || !(space.IsDeleteSpace());
  104. //限制所用空间的阶段
  105. if (isspace)
  106. {
  107. //增加过滤效率,如果上一步正确菜继续往下执行。
  108. isspace = space.IsPhase1Space();
  109. }
  110. if (isspace)
  111. {
  112. isspace = space.IsViewLevel();
  113. }
  114. }
  115. return isspace;
  116. }
  117. }
  118. }