12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
-
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Electrical;
- using FWindSoft.SystemExtensions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- public static class CableTrayExtension
- {
- /// <summary>
- /// 获取项目中所有桥架类型
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<CableTrayType> GetCableTrays(this Document doc)
- {
- List<CableTrayType> list = doc.GetElements<CableTrayType>();
- return list;
- }
- /// <summary>
- /// 桥架线槽方向旋转
- /// </summary>
- /// <param name="cableTray"></param>
- /// <param name="angle"></param>
- public static void RotateNormal(this CableTray cableTray, double angle)
- {
- Line line = cableTray.GetLocationLine();
- XYZ bottom = line.StartPoint();
- XYZ top = line.EndPoint();
- XYZ axis = bottom.NewLine(top).Direction;
- XYZ direction = cableTray.CurveNormal;
- cableTray.CurveNormal = direction.RotateVector(axis, angle);
- }
- /// <summary>
- /// 判断桥架截面是否相同
- /// </summary>
- /// <param name="cableTray"></param>
- /// <param name="cableTraySecond"></param>
- /// <returns></returns>
- public static bool IsSectionSameSize(this CableTray first, CableTray second)
- {
- return first.Height.IsEqual(second.Height) && first.Width.IsEqual(second.Width);
- }
- /// <summary>
- /// 取桥架的系统类型名称,顺序优先
- /// </summary>
- /// <param name="cableTrays"></param>
- /// <returns></returns>
- public static string GetSystemName(this List<CableTray> cableTrays)
- {
- var reuslt = string.Empty;
- if (cableTrays == null)
- return reuslt;
- foreach (var cableTray in cableTrays)
- {
- string str = cableTray.GetParameterString("系统类型");
- if (!string.IsNullOrWhiteSpace(str))
- return str;
- }
- return reuslt;
- }
- /// <summary>
- /// 获取垂直桥架角度
- /// </summary>
- /// <param name="cableTray"></param>
- /// <returns>如果桥架垂直返回正确角度,如果桥架竖直,返回π/2</returns>
- public static double GetVerAngle(this CableTray cableTray)
- {
- if (cableTray == null)
- return 0;
- double defalut = Math.PI / 2;
- var line = cableTray.GetLocationLine();
- XYZ start = line.StartPoint();
- XYZ end = line.EndPoint();
- if (!start.IsEqual2(end))
- {
- return defalut;
- }
- XYZ normal = cableTray.CurveNormal;
- //此方法有漏洞,桥架垂直时使用
- return XYZ.BasisX.AngleOnPlaneTo(normal, XYZ.BasisZ);
- }
- }
- }
|