SpaceExtension.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* ==============================================================================
  2. * 功能描述:SpaceExtension
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/26 17:40:25
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Autodesk.Revit.DB;
  12. using Autodesk.Revit.DB.Mechanical;
  13. using SAGA.RevitUtils;
  14. using SAGA.RevitUtils.Extends;
  15. namespace RevitToJBim.Extension
  16. {
  17. /// <summary>
  18. /// SpaceExtension
  19. /// </summary>
  20. public static class SpaceExtension
  21. {
  22. public readonly static string UseablePhaseName = "阶段1";
  23. /// <summary>
  24. /// 获取系统使用的阶段Id
  25. /// </summary>
  26. /// <param name="doc"></param>
  27. /// <returns></returns>
  28. public static ElementId GetUsePhaseId(this Document doc)
  29. {
  30. var phase = GetUsePhase(doc);
  31. if (phase == null)
  32. {
  33. return ElementId.InvalidElementId;
  34. }
  35. return phase.Id;
  36. }
  37. /// <summary>
  38. /// 获取系统使用的阶段
  39. /// </summary>
  40. /// <param name="doc"></param>
  41. /// <returns></returns>
  42. public static Phase GetUsePhase(this Document doc)
  43. {
  44. var elements = doc.GetElements<Phase>(BuiltInCategory.OST_Phases);
  45. foreach (var element in elements)
  46. {
  47. var tempName = element.Name.Replace(" ", "").Trim();
  48. if (UseablePhaseName == tempName)
  49. {
  50. return element;
  51. }
  52. }
  53. return null;
  54. }
  55. public static ElementId GetCurrentPhaseId(this Space space)
  56. {
  57. return space.GetParameterElementId(BuiltInParameter.ROOM_PHASE_ID) ?? ElementId.InvalidElementId;
  58. }
  59. /// <summary>
  60. /// 判断是否是阶段1的空间
  61. /// </summary>
  62. /// <param name="space"></param>
  63. /// <returns></returns>
  64. public static bool IsPhase1Space(this Space space)
  65. {
  66. var doc = space.Document;
  67. var useId = GetUsePhaseId(doc);
  68. return space.GetCurrentPhaseId() == useId;
  69. }
  70. /// <summary>
  71. /// 空间标高是否是当前使用视图标高
  72. /// </summary>
  73. /// <param name="space"></param>
  74. /// <returns></returns>
  75. public static bool IsViewLevel(this Space space)
  76. {
  77. var doc = space.Document;
  78. var useViewId = doc.GetUseView();
  79. if (useViewId == null)
  80. {
  81. return false;
  82. }
  83. return space.Level?.Id == useViewId.GenLevel?.Id;
  84. }
  85. }
  86. }