123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit
- {
- public static class DuctExtension
- {
- /// <summary>
- /// 获取风管系统类型(非枚举)
- /// </summary>
- /// <param name="duct">风管</param>
- /// <returns></returns>
- public static MechanicalSystemType GetMechanicalSystemType(this Duct duct)
- {
- var id = duct.GetParameterElementId(BuiltInParameter.RBS_DUCT_SYSTEM_TYPE_PARAM);
- return duct.Document.GetElement(id) as MechanicalSystemType;
- }
- /// <summary>
- /// 获取风管系统分类
- /// </summary>
- /// <param name="duct"></param>
- /// <returns></returns>
- public static DuctSystemType GetDuctSystemType(this Duct duct)
- {
- var ductSystem = duct.MEPSystem as MechanicalSystem;
- if (ductSystem != null)
- return ductSystem.SystemType;
- return DuctSystemType.UndefinedSystemType;
- }
- /// <summary>
- /// 获取风管的朝向
- /// </summary>
- /// <param name="duct"></param>
- /// <returns></returns>
- public static XYZ GetCurveNormal(this Duct duct)
- {
- //通过connector basizY的方向去确定朝向
- Connector connector = duct.GetFirstConnector(c=>c.ConnectorType==ConnectorType.End);
- return connector.CoordinateSystem.BasisY.Negate();
- }
- /// <summary>
- /// 设置风管的朝向
- /// </summary>
- /// <param name="duct"></param>
- /// <param name="normal"></param>
- public static void SetCurveNormal(this Duct duct, XYZ normal)
- {
- XYZ sorce = duct.GetCurveNormal();
- Line axis = duct.GetLocationLine();
- double angle = sorce.AngleOnPlaneTo(normal, axis.Direction.Normalize());
- duct.Rotate(axis, angle);
- }
- /// <summary>
- /// 获取风管的最长尺寸
- /// </summary>
- /// <param name="duct"></param>
- /// <returns></returns>
- public static double GetLongestSize(this Duct duct)
- {
- double tempDia = duct.GetParameterDouble(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM).MmFromFt();
- double tempWidth = duct.GetParameterDouble(BuiltInParameter.RBS_CURVE_WIDTH_PARAM).MmFromFt();
- double tempHeight = duct.GetParameterDouble(BuiltInParameter.RBS_CURVE_HEIGHT_PARAM).MmFromFt();
- double length = tempHeight > tempWidth ? tempHeight : tempWidth;
- length = tempDia > length ? tempDia : length;
- return length;
- }
- /// <summary>
- /// 判断给定的风管集合的垂直对齐方式
- /// </summary>
- /// <param name="ducts">风管集合</param>
- /// <returns>返回垂直对齐的标识(-1,底对齐;0,一般处理;1,顶对齐。)</returns>
- public static int GetVerAlignType(this List<Duct> ducts)
- {
- int flag = 0;
- //List<Connector> connectors = ducts.Select(d => d.GetConnectors()[0]).ToList();
- //List<Tuple<XYZ, XYZ, double>> listTuple = new List<Tuple<XYZ, XYZ, double>>();
- //foreach (var connector in connectors)
- //{
- // double length = connector.Shape == ConnectorProfileType.Round ? connector.Radius * 2 : connector.Height;
- // listTuple.Add(new Tuple<XYZ, XYZ, double>(connector.Origin, connector.CoordinateSystem.BasisY, length));
- //}
- //if (listTuple.Count == 0)
- // return flag;
- //Tuple<XYZ, XYZ, double> baseTuple = listTuple[0];
- //if (listTuple.Any(t => !t.Item2.IsParallel(baseTuple.Item2)))
- // return 0;
- //Line baseLine = baseTuple.Item1.NewLine(baseTuple.Item1.OffsetPoint(baseTuple.Item2, 1000));
- //XYZ baseOrigion = baseLine.GetProjectPt(baseTuple.Item1, true);
- //if (listTuple.All(t => baseLine.GetProjectPt(t.Item1, true).IsEqual(baseOrigion, 0.001)))
- //{
- // return 0;
- //}
- //XYZ bottom = baseTuple.Item1.OffsetPoint(baseTuple.Item2, baseTuple.Item3 / 2);
- //XYZ bottomProject = baseLine.GetProjectPt(bottom, true);
- //if (
- // listTuple.All(
- // t =>
- // baseLine.GetProjectPt(t.Item1.OffsetPoint(t.Item2, t.Item3 / 2), true)
- // .IsEqual(bottomProject, 0.001)))
- //{
- // return -1;
- //}
- //XYZ top = baseTuple.Item1.OffsetPoint(baseTuple.Item2.Negate(), baseTuple.Item3 / 2);
- //XYZ topProject = baseLine.GetProjectPt(top, true);
- //if (
- // listTuple.All(
- // t =>
- // baseLine.GetProjectPt(t.Item1.OffsetPoint(t.Item2.Negate(), t.Item3 / 2), true)
- // .IsEqual(topProject, 0.001)))
- //{
- // return 1;
- //}
- return flag;
- }
- /// <summary>
- /// 获取风管实例截面类型
- /// </summary>
- /// <param name="duct">指定风管</param>
- /// <returns>风管截面形状</returns>
- public static DuctShape GetDuctShape(this Duct duct)
- {
- DuctShape shape = DuctShape.Rectangular;
- var connector = duct.GetFirstConnector(c=>c.ConnectorType==ConnectorType.End);
- switch (connector.Shape)
- {
- case ConnectorProfileType.Oval:
- {
- shape = DuctShape.Oval;
- break;
- }
- case ConnectorProfileType.Round:
- {
- shape = DuctShape.Round;
- break;
- }
- case ConnectorProfileType.Rectangular:
- {
- shape = DuctShape.Rectangular;
- break;
- }
- }
- return shape;
- }
- /// <summary>
- /// 获取垂直风管角度
- /// </summary>
- /// <param name="duct"></param>
- /// <returns>如果风管垂直返回正确角度,如果风管竖直,返回π/2</returns>
- public static double GetVerAngle(this Duct duct)
- {
- if (duct == null)
- return 0;
- double defalut = Math.PI / 2;
- var line = duct.GetLocationLine();
- XYZ start = line.StartPoint();
- XYZ end = line.EndPoint();
- if (!start.IsEqual2(end))
- {
- return defalut;
- }
- XYZ normal = duct.GetCurveNormal();
- //不封装,是为了保证使用的严谨性,时刻记住是三维
- return XYZ.BasisX.AngleOnPlaneTo(normal, XYZ.BasisZ);
- }
- /// <summary>
- /// 根据界面类型获取所需要的尺寸
- /// </summary>
- /// <param name="doc"></param>
- /// <param name="shape"></param>
- /// <returns></returns>
- public static List<double> GetDuctSizes(this Document doc, DuctShape shape)
- {
- List<double> sizes = new List<double>();
- DuctSizeSettings setting = DuctSizeSettings.GetDuctSizeSettings(doc);
- if (setting != null)
- {
- sizes = setting[shape].Select(size => size.NominalDiameter.MmFromFt()).ToList();
- }
- return sizes;
- }
- /// <summary>
- /// 获取项目中设置的空气密度
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static double GetAirDensity(this Document doc)
- {
- double airDensity = 1;
- List<double> sizes = new List<double>();
- DuctSettings setting = DuctSettings.GetDuctSettings(doc);
- if (setting != null)
- {
- airDensity = setting.AirDensity;
- }
- //单位转换的问题
- return 0;//airDensity.FromApi(DisplayUnitType.DUT_KILOGRAMS_PER_CUBIC_METER);
- }
-
- /// <summary>
- /// 获取制定风管类型的截面类型
- /// </summary>
- /// <param name="ductType">风管类型</param>
- /// <returns></returns>
- public static DuctShape GetDuctShape(this DuctType ductType)
- {
- string strShape = ductType.GetParameterString(BuiltInParameter.ALL_MODEL_FAMILY_NAME);
- do
- {
- if ("矩形风管".Equals(strShape))
- {
- return DuctShape.Rectangular;
- }
- if ("圆形风管".Equals(strShape))
- {
- return DuctShape.Round;
- }
- if ("椭圆形风管".Equals(strShape))
- {
- return DuctShape.Oval;
- }
- } while (false);
- throw new Exception("获取风管类型截面出错");
- }
- /// <summary>
- /// 获取项目中所有风管类型
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<DuctType> GetDuctTypes(this Document doc)
- {
- List<DuctType> list = doc.GetElements<DuctType>();
- return list;
- }
- /// <summary>
- /// 获取项目中所有风管类型
- /// </summary>
- /// <param name="doc"></param>
- /// <param name="shape"></param>
- /// <returns></returns>
- public static List<DuctType> GetDuctTypes(this Document doc, DuctShape shape)
- {
- List<DuctType> list = doc.GetDuctTypes();
- return list.Where(type => type.GetDuctShape() == shape).ToList();
- }
- /// <summary>
- /// 获取所有的软管类型
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<FlexDuctType> GetFlexDuctTypes(this Document doc)
- {
- List<FlexDuctType> list = doc.GetElements<FlexDuctType>();
- return list;
- }
- }
- }
|