123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Electrical;
- using Autodesk.Revit.DB.Mechanical;
- using Autodesk.Revit.DB.Plumbing;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FWindSoft.Revit.Utils
- {
- /// <summary>
- /// 管件类型枚举
- /// </summary>
- public enum FittingType
- {
- /// <summary>
- /// 未定
- /// </summary>
- Undefined = -1,
- /// <summary>
- /// 弯头
- /// </summary>
- Elbows = 1,
- /// <summary>
- /// 三通
- /// </summary>
- Junctions = 2,
- /// <summary>
- /// 四通
- /// </summary>
- Crosses = 3,
- /// <summary>
- /// 变径
- /// </summary>
- Transitions = 4,
- /// <summary>
- /// 活接头
- /// </summary>
- Unions = 5,
- /// <summary>
- /// 方形到原型变径
- /// </summary>
- TransitionsRectangularToRound = 7,
- /// <summary>
- /// 方形到椭圆变径
- /// </summary>
- TransitionsRectangularToOval = 8,
- /// <summary>
- /// 椭圆到原型变径
- /// </summary>
- TransitionsOvalToRound = 9,
- /// <summary>
- /// 堵头
- /// </summary>
- Caps = 10
- }
- /// <summary>
- /// 管件工具
- /// </summary>
- public static class FittingUtils
- {
- #region 私有方法
- /// <summary>
- /// 判断传入类型的的分类
- /// </summary>
- /// <param name="mepCurveType"></param>
- /// <returns>-1 无效;0 线管桥架;1水管风管 </returns>
- private static int JudgeType(MEPCurveType mepCurveType)
- {
- int flag = -1;
- if (mepCurveType is ConduitType || mepCurveType is CableTrayType)
- {
- return 0;
- }
- if (mepCurveType is PipeType || mepCurveType is DuctType)
- {
- return 1;
- }
- return flag;
- }
- /// <summary>
- /// FittingType转换成布线规则
- /// </summary>
- /// <param name="fittingType"></param>
- /// <returns></returns>
- private static RoutingPreferenceRuleGroupType ConvertToRuleType(FittingType fittingType)
- {
- return (RoutingPreferenceRuleGroupType)fittingType;
- }
- /// <summary>
- /// FittingType转换成对应参数
- /// </summary>
- /// <param name="fittingType"></param>
- /// <returns></returns>
- private static BuiltInParameter ConvertToBitParameter(FittingType fittingType)
- {
- BuiltInParameter use = BuiltInParameter.INVALID;
- switch (fittingType)
- {
- case FittingType.Elbows:
- use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_BEND_PARAM;
- break;
- case FittingType.Junctions:
- use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_TEE_PARAM;
- break;
- case FittingType.Crosses:
- use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_CROSS_PARAM;
- break;
- case FittingType.Transitions:
- use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_TRANSITION_PARAM;
- break;
- case FittingType.Unions:
- use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_UNION_PARAM;
- break;
- case FittingType.Caps:
- use = BuiltInParameter.RBS_CURVETYPE_DEFAULT_CAP_PARAM;
- break;
- default:
- break;
- }
- return use;
- }
- #endregion
- /// <summary>
- /// MepCurveType增加指定类型的管件
- /// </summary>
- /// <param name="mepCurveType"></param>
- /// <param name="fittingType">管件类型</param>
- /// <param name="elementId"></param>
- public static void AddFitting(MEPCurveType mepCurveType, FittingType fittingType, ElementId elementId)
- {
- var flag = JudgeType(mepCurveType);
- elementId = elementId??ElementId.InvalidElementId;
- if (flag==0)
- {
- mepCurveType.AddFitting(ConvertToBitParameter(fittingType), elementId);
- }
- else if(flag==1)
- {
- mepCurveType.AddRoutingRule(ConvertToRuleType(fittingType), elementId);
- }
- }
- /// <summary>
- /// MepCurveType移除指定管件
- /// </summary>
- /// <param name="mepCurveType"></param>
- /// <param name="fittingType"></param>
- public static void RemoveFitting(MEPCurveType mepCurveType, FittingType fittingType)
- {
- var flag = JudgeType(mepCurveType);
- if (flag == 0)
- {
- mepCurveType.RemoveFitting(ConvertToBitParameter(fittingType));
- }
- else if (flag == 1)
- {
- mepCurveType.RemoveRoutingRule(ConvertToRuleType(fittingType));
- }
- }
- /// <summary>
- /// MepCurveType获取指定管件
- /// </summary>
- /// <param name="mepCurveType"></param>
- /// <param name="fittingType"></param>
- /// <returns></returns>
- public static ElementId GetFitting(MEPCurveType mepCurveType, FittingType fittingType)
- {
- ElementId elmentId = null;
- var flag = JudgeType(mepCurveType);
- if (flag == 0)
- {
- elmentId=mepCurveType.GetFitting(ConvertToBitParameter(fittingType));
- }
- else if (flag == 1)
- {
- var rule = mepCurveType.GetRoutingRule(ConvertToRuleType(fittingType));
- if(rule!=null)
- {
- elmentId = rule.MEPPartId;
- }
- }
- return elmentId;
- }
- }
- }
|