CableTrayExtension.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 
  2. using Autodesk.Revit.DB;
  3. using Autodesk.Revit.DB.Electrical;
  4. using FWindSoft.SystemExtensions;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace FWindSoft.Revit
  11. {
  12. public static class CableTrayExtension
  13. {
  14. /// <summary>
  15. /// 获取项目中所有桥架类型
  16. /// </summary>
  17. /// <param name="doc"></param>
  18. /// <returns></returns>
  19. public static List<CableTrayType> GetCableTrays(this Document doc)
  20. {
  21. List<CableTrayType> list = doc.GetElements<CableTrayType>();
  22. return list;
  23. }
  24. /// <summary>
  25. /// 桥架线槽方向旋转
  26. /// </summary>
  27. /// <param name="cableTray"></param>
  28. /// <param name="angle"></param>
  29. public static void RotateNormal(this CableTray cableTray, double angle)
  30. {
  31. Line line = cableTray.GetLocationLine();
  32. XYZ bottom = line.StartPoint();
  33. XYZ top = line.EndPoint();
  34. XYZ axis = bottom.NewLine(top).Direction;
  35. XYZ direction = cableTray.CurveNormal;
  36. cableTray.CurveNormal = direction.RotateVector(axis, angle);
  37. }
  38. /// <summary>
  39. /// 判断桥架截面是否相同
  40. /// </summary>
  41. /// <param name="cableTray"></param>
  42. /// <param name="cableTraySecond"></param>
  43. /// <returns></returns>
  44. public static bool IsSectionSameSize(this CableTray first, CableTray second)
  45. {
  46. return first.Height.IsEqual(second.Height) && first.Width.IsEqual(second.Width);
  47. }
  48. /// <summary>
  49. /// 取桥架的系统类型名称,顺序优先
  50. /// </summary>
  51. /// <param name="cableTrays"></param>
  52. /// <returns></returns>
  53. public static string GetSystemName(this List<CableTray> cableTrays)
  54. {
  55. var reuslt = string.Empty;
  56. if (cableTrays == null)
  57. return reuslt;
  58. foreach (var cableTray in cableTrays)
  59. {
  60. string str = cableTray.GetParameterString("系统类型");
  61. if (!string.IsNullOrWhiteSpace(str))
  62. return str;
  63. }
  64. return reuslt;
  65. }
  66. /// <summary>
  67. /// 获取垂直桥架角度
  68. /// </summary>
  69. /// <param name="cableTray"></param>
  70. /// <returns>如果桥架垂直返回正确角度,如果桥架竖直,返回π/2</returns>
  71. public static double GetVerAngle(this CableTray cableTray)
  72. {
  73. if (cableTray == null)
  74. return 0;
  75. double defalut = Math.PI / 2;
  76. var line = cableTray.GetLocationLine();
  77. XYZ start = line.StartPoint();
  78. XYZ end = line.EndPoint();
  79. if (!start.IsEqual2(end))
  80. {
  81. return defalut;
  82. }
  83. XYZ normal = cableTray.CurveNormal;
  84. //此方法有漏洞,桥架垂直时使用
  85. return XYZ.BasisX.AngleOnPlaneTo(normal, XYZ.BasisZ);
  86. }
  87. }
  88. }