ElementExtension.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. public static string GetFamilySymbolName(this Element element)
  29. {
  30. return element.GetFamilySymbol()?.Name;
  31. }
  32. /// <summary>
  33. /// 获取设备的种族类型编码 ATFC
  34. /// 族名称的命名规则:ATFC-风机盘管
  35. /// </summary>
  36. /// <returns></returns>
  37. public static string GetFamilyCode(this Element element)
  38. {
  39. string code = "";
  40. if (element is FamilyInstance fi)
  41. {
  42. string familyName = fi.GetFamilyName();
  43. if (familyName == null) return code;
  44. //族名称的命名规则:ATFC-风机盘管
  45. int index = familyName.IndexOf('-');
  46. if (index != -1 && index + 1 != familyName.Length)
  47. code = familyName.Substring(0, familyName.IndexOf('-'));
  48. //移除前面和后面的空格
  49. code = code.Trim();
  50. }
  51. return code;
  52. }
  53. /// <summary>
  54. /// 判断是否为设备 设备族为4位
  55. /// ATVR - 多联机 - 室内机 - 双向气流 - 天花板嵌入式
  56. /// </summary>
  57. /// <param name="fi"></param>
  58. /// <returns></returns>
  59. public static bool IsEquipment(this Element element)
  60. {
  61. bool result = false;
  62. if (element is FamilyInstance fi)
  63. {
  64. var family = fi.GetFamilyName();
  65. result = Regex.IsMatch(family, $"{MBIRegexPattern.IsEquip}");
  66. }
  67. return result;
  68. }
  69. /// <summary>
  70. /// 判断是否为设备部件 设备族为6位
  71. /// </summary>
  72. /// <param name="fi"></param>
  73. /// <returns></returns>
  74. public static bool IsEquipmentPart(this Element element)
  75. {
  76. bool result = false;
  77. if (element is FamilyInstance fi)
  78. {
  79. var family = fi.GetFamilyName();
  80. result = Regex.IsMatch(family, $"{MBIRegexPattern.IsEquipPart}");
  81. }
  82. return result;
  83. }
  84. /// <summary>
  85. /// 判断是否为信标
  86. /// </summary>
  87. /// <param name="elem"></param>
  88. /// <returns></returns>
  89. public static bool IsBeacon(this Element elem)
  90. {
  91. var family = elem.GetFamilyName();
  92. return family != null && (Regex.IsMatch(family, MBIRegexPattern.IsBeacon));
  93. }
  94. /// <summary>
  95. /// 判断是否为空间,判断周长是否为零
  96. /// 如果周长为零,是删除的空间
  97. /// </summary>
  98. /// <param name="elem"></param>
  99. /// <param name="ischeckzero">是否检查周长为零</param>
  100. /// <returns></returns>
  101. public static bool IsSpace(this Element elem, bool ischeckzero = true)
  102. {
  103. var isspace = false;
  104. if (elem is Space space)
  105. {
  106. //空间比较特殊,周长为零就相当于删除
  107. isspace = !ischeckzero || !(space.IsDeleteSpace());
  108. string id = space.Id.ToString();
  109. //限制所用空间的阶段
  110. if (isspace)
  111. {
  112. //增加过滤效率,如果上一步正确菜继续往下执行。
  113. isspace = space.IsPhase1Space();
  114. }
  115. if (isspace)
  116. {
  117. isspace = space.IsViewLevel();
  118. }
  119. }
  120. return isspace;
  121. }
  122. }
  123. }