RotationStrategy.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Autodesk.Revit.DB;
  2. using FWindSoft.SystemExtensions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace FWindSoft.Revit.Mep
  9. {
  10. /// <summary>
  11. /// 旋转策略
  12. /// </summary>
  13. public class RotationStrategy:List<RotationItem>
  14. {
  15. public RotationStrategy()
  16. { }
  17. public RotationStrategy(XYZ location, XYZ axis, double angle)
  18. {
  19. this.Add(new RotationItem(location,axis, angle));
  20. }
  21. public RotationStrategy(List<RotationItem> rotationItems):base(rotationItems)
  22. {
  23. }
  24. /// <summary>
  25. /// 向旋转策略中,增加旋转项
  26. /// </summary>
  27. /// <param name="axis"></param>
  28. /// <param name="angle"></param>
  29. public void Add(XYZ location, XYZ axis, double angle)
  30. {
  31. this.Add(new RotationItem(location,axis, angle));
  32. }
  33. /// <summary>
  34. /// 旋转指定实例
  35. /// </summary>
  36. /// <param name="familyInstance"></param>
  37. public void Rotate(FamilyInstance familyInstance)
  38. {
  39. this.ForEach(ri => ri.Rotate(familyInstance));
  40. }
  41. }
  42. /// <summary>
  43. /// 旋转数据
  44. /// </summary>
  45. public class RotationItem
  46. {
  47. public RotationItem(XYZ location,XYZ axis,double angle)
  48. {
  49. Location = location;
  50. Axis = axis;
  51. Angle = angle;
  52. }
  53. /// <summary>
  54. /// 旋转中心
  55. /// </summary>
  56. public XYZ Location { get; set; }
  57. /// <summary>
  58. /// 旋转轴
  59. /// </summary>
  60. public XYZ Axis { get; set; }
  61. /// <summary>
  62. /// 旋转角度
  63. /// </summary>
  64. public double Angle { get; set; }
  65. /// <summary>
  66. /// 旋转指定familyInstance
  67. /// </summary>
  68. /// <param name="familyInstance"></param>
  69. public void Rotate(FamilyInstance familyInstance)
  70. {
  71. if(Angle.IsEqual(0))
  72. {//暂时粗糙判断,不考虑2π周期性的东西
  73. return;
  74. }
  75. var line = Line.CreateUnbound(Location, Axis);
  76. ElementTransformUtils.RotateElement(familyInstance.Document, familyInstance.Id, line, Angle);
  77. }
  78. }
  79. }