WallExtend.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /////////////////////////////////////////////
  2. //Copyright (c) 2016, SAGA
  3. //All rights reserved.
  4. //文件名称: WallExtend.cs
  5. //文件描述: 墙操作常用扩展方法
  6. //创 建 者: 刘森
  7. //创建日期: 2016-05-03
  8. //版 本 号:1.0.0.0
  9. /////////////////////////////////////////////
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using Autodesk.Revit.DB;
  13. namespace SAGA.RevitUtils.Extends
  14. {
  15. public static class WallExtend
  16. {
  17. /// <summary>
  18. /// 墙底部标高
  19. /// </summary>
  20. /// <param name="wall"></param>
  21. /// <returns></returns>
  22. public static Level GetBaseLevel(this Wall wall)
  23. {
  24. ElementId id = wall.GetBaseLevelId();
  25. if (id != ElementId.InvalidElementId && id != null)
  26. {
  27. return wall.Document.GetElement(wall.GetBaseLevelId()) as Level;
  28. }
  29. return null;
  30. }
  31. /// <summary>
  32. /// 墙面积(㎡)
  33. /// </summary>
  34. /// <returns></returns>
  35. public static double GetArea(this Wall wall)
  36. {
  37. return wall.GetParameterDouble(BuiltInParameter.HOST_AREA_COMPUTED).FromApi(DisplayUnitType.DUT_SQUARE_METERS);
  38. }
  39. /// <summary>
  40. /// 墙底部标高Id
  41. /// </summary>
  42. /// <param name="wall"></param>
  43. /// <returns></returns>
  44. public static ElementId GetBaseLevelId(this Wall wall)
  45. {
  46. return wall.GetParameterElementId(BuiltInParameter.WALL_BASE_CONSTRAINT);
  47. }
  48. /// <summary>
  49. /// 墙顶部标高
  50. /// </summary>
  51. /// <param name="wall"></param>
  52. /// <returns></returns>
  53. public static Level GetTopLevel(this Wall wall)
  54. {
  55. ElementId id = wall.GetTopLevelId();
  56. if (id != ElementId.InvalidElementId && id != null)
  57. {
  58. return wall.Document.GetElement(wall.GetTopLevelId()) as Level;
  59. }
  60. return null;
  61. }
  62. /// <summary>
  63. /// 墙顶部标高Id
  64. /// </summary>
  65. /// <param name="wall"></param>
  66. /// <returns></returns>
  67. public static ElementId GetTopLevelId(this Wall wall)
  68. {
  69. return wall.GetParameterElementId(BuiltInParameter.WALL_HEIGHT_TYPE);
  70. }
  71. /// <summary>
  72. /// 墙底部偏移
  73. /// </summary>
  74. /// <returns></returns>
  75. public static double GetBaseOffSet(this Wall wall)
  76. {
  77. return wall.GetParameterDouble(BuiltInParameter.WALL_BASE_OFFSET);
  78. }
  79. /// <summary>
  80. /// 获取底部高度
  81. /// </summary>
  82. /// <param name="wall"></param>
  83. /// <returns></returns>
  84. public static double GetBaseStaticHeight(this Wall wall)
  85. {
  86. return wall.GetBaseLevel().Elevation + wall.GetBaseOffSet();
  87. }
  88. /// <summary>
  89. /// 获取顶部高度
  90. /// </summary>
  91. /// <param name="wall"></param>
  92. /// <returns></returns>
  93. public static double GetTopStaticHeight(this Wall wall)
  94. {
  95. return wall.GetTopLevel().Elevation + wall.GetTopOffSet();
  96. }
  97. /// <summary>
  98. /// 墙顶部偏移
  99. /// </summary>
  100. /// <param name="wall"></param>
  101. /// <returns></returns>
  102. public static double GetTopOffSet(this Wall wall)
  103. {
  104. return wall.GetParameterDouble(BuiltInParameter.WALL_TOP_OFFSET);
  105. }
  106. /// <summary>
  107. /// 设置墙底部偏移
  108. /// </summary>
  109. /// <param name="offSet">偏移值(英寸)</param>
  110. /// <returns></returns>
  111. public static void SetBaseOffSet(this Wall wall, double offSet)
  112. {
  113. wall.SetParameter(BuiltInParameter.WALL_BASE_OFFSET, offSet);
  114. }
  115. /// <summary>
  116. /// 设置墙顶部偏移
  117. /// </summary>
  118. /// <param name="wall"></param>
  119. /// <param name="offset">顶部偏移(英寸)</param>
  120. public static void SetTopOffSet(this Wall wall, double offset)
  121. {
  122. wall.SetParameter(BuiltInParameter.WALL_TOP_OFFSET, offset);
  123. }
  124. public static void SetMaterial(this WallType wallTyp, ElementId materialId)
  125. {
  126. CompoundStructure compoundStructure = wallTyp.GetCompoundStructure();
  127. List<CompoundStructureLayer> layerList = compoundStructure.GetLayers().ToList();
  128. int coreIndex = compoundStructure.GetLastCoreLayerIndex();
  129. compoundStructure.SetMaterialId(coreIndex, materialId);
  130. wallTyp.SetCompoundStructure(compoundStructure);
  131. }
  132. }
  133. }