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
{
///
/// 获取项目中所有桥架类型
///
///
///
public static List GetCableTrays(this Document doc)
{
List list = doc.GetElements();
return list;
}
///
/// 桥架线槽方向旋转
///
///
///
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);
}
///
/// 判断桥架截面是否相同
///
///
///
///
public static bool IsSectionSameSize(this CableTray first, CableTray second)
{
return first.Height.IsEqual(second.Height) && first.Width.IsEqual(second.Width);
}
///
/// 取桥架的系统类型名称,顺序优先
///
///
///
public static string GetSystemName(this List 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;
}
///
/// 获取垂直桥架角度
///
///
/// 如果桥架垂直返回正确角度,如果桥架竖直,返回π/2
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);
}
}
}