12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using Autodesk.Revit.DB;
- using FWindSoft.SystemExtensions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit.Mep
- {
- /// <summary>
- /// 旋转策略
- /// </summary>
- public class RotationStrategy:List<RotationItem>
- {
- public RotationStrategy()
- { }
- public RotationStrategy(XYZ location, XYZ axis, double angle)
- {
- this.Add(new RotationItem(location,axis, angle));
- }
- public RotationStrategy(List<RotationItem> rotationItems):base(rotationItems)
- {
- }
- /// <summary>
- /// 向旋转策略中,增加旋转项
- /// </summary>
- /// <param name="axis"></param>
- /// <param name="angle"></param>
- public void Add(XYZ location, XYZ axis, double angle)
- {
- this.Add(new RotationItem(location,axis, angle));
- }
- /// <summary>
- /// 旋转指定实例
- /// </summary>
- /// <param name="familyInstance"></param>
- public void Rotate(FamilyInstance familyInstance)
- {
- this.ForEach(ri => ri.Rotate(familyInstance));
- }
- }
- /// <summary>
- /// 旋转数据
- /// </summary>
- public class RotationItem
- {
- public RotationItem(XYZ location,XYZ axis,double angle)
- {
- Location = location;
- Axis = axis;
- Angle = angle;
- }
- /// <summary>
- /// 旋转中心
- /// </summary>
- public XYZ Location { get; set; }
- /// <summary>
- /// 旋转轴
- /// </summary>
- public XYZ Axis { get; set; }
- /// <summary>
- /// 旋转角度
- /// </summary>
- public double Angle { get; set; }
- /// <summary>
- /// 旋转指定familyInstance
- /// </summary>
- /// <param name="familyInstance"></param>
- public void Rotate(FamilyInstance familyInstance)
- {
- if(Angle.IsEqual(0))
- {//暂时粗糙判断,不考虑2π周期性的东西
- return;
- }
- var line = Line.CreateUnbound(Location, Axis);
- ElementTransformUtils.RotateElement(familyInstance.Document, familyInstance.Id, line, Angle);
- }
-
- }
- }
|