123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- 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
- {
- public static class MepCurveTypeExtension
- {
- #region 水管风管类型布线规则维护
- /// <summary>
- /// 增加MepCurve优先规则
- /// </summary>
- /// <param name="pipeDuctType">MepCurve类型</param>
- /// <param name="groupType">规则分组</param>
- /// <param name="elementId">规则使用的element</param>
- /// <param name="index">规则在分组中的位置</param>
- /// <returns>-1操作类型不符</returns>
- public static int AddRoutingRule(this MEPCurveType pipeDuctType, RoutingPreferenceRuleGroupType groupType,
- ElementId elementId, int index = 0)
- {
- if (pipeDuctType is PipeType || pipeDuctType is DuctType)
- {
- RoutingPreferenceManager manager = pipeDuctType.RoutingPreferenceManager;
- if (null != manager)
- {
- RoutingPreferenceRule rule = new RoutingPreferenceRule(elementId, "");
- rule.AddCriterion(PrimarySizeCriterion.All());
- manager.AddRule(groupType, rule, 0);
- }
- return index;
- }
- else
- {
- return -1;
- }
- }
- /// <summary>
- /// 移除MepCurve规则分组中制定位置的规则
- /// </summary>
- /// <param name="pipeDuctType">MepCurve类型</param>
- /// <param name="groupType">规则分组</param>
- /// <param name="index">规则在该分组中的位置</param>
- /// <returns>-1操作类型不符</returns>
- public static int RemoveRoutingRule(this MEPCurveType pipeDuctType, RoutingPreferenceRuleGroupType groupType,
- int index = 0)
- {
- if (pipeDuctType is PipeType || pipeDuctType is DuctType)
- {
- RoutingPreferenceManager manager = pipeDuctType.RoutingPreferenceManager;
- if (null != manager)
- {
- manager.RemoveRule(groupType, index);
- }
- }
- else
- {
- index = -1;
- }
- return index;
- }
- /// <summary>
- /// 获取MepCurve优先规则分组中指定位置的规则
- /// </summary>
- /// <param name="pipeDuctType"></param>
- /// <param name="groupType"></param>
- /// <param name="index"></param>
- /// <returns></returns>
- public static RoutingPreferenceRule GetRoutingRule(this MEPCurveType pipeDuctType,
- RoutingPreferenceRuleGroupType groupType, int index = 0)
- {
- RoutingPreferenceManager manager = pipeDuctType.RoutingPreferenceManager;
- RoutingPreferenceRule rule = null;
- if (pipeDuctType is PipeType || pipeDuctType is DuctType)
- {
- if (null != manager)
- {
- rule = manager.GetRule(groupType, index);
- }
- }
- return rule;
- }
- #endregion
- #region 线管桥架连接件类型维护
- /// <summary>
- /// 修改桥架线管指定连接件的参数
- /// </summary>
- /// <param name="cableTrayConduitType">桥架线管</param>
- /// <param name="parameter">连接件类型参数</param>
- /// <param name="elementId">规则使用的element</param>
- /// <returns></returns>
- public static void AddFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter,ElementId elementId)
- {
- if(cableTrayConduitType is ConduitType|| cableTrayConduitType is CableTrayType)
- {
- if (null != cableTrayConduitType)
- {
- cableTrayConduitType.SetParameter(parameter, elementId);
- }
- }
- }
- /// <summary>
- /// 移除桥架线管指定连接件的参数
- /// </summary>
- /// <param name="cableTrayConduitType">桥架线管</param>
- /// <param name="parameter">连接件类型参数</param>
- /// <returns></returns>
- public static void RemoveFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter)
- {
- if (cableTrayConduitType is ConduitType || cableTrayConduitType is CableTrayType)
- {
- if (null != cableTrayConduitType)
- {
- cableTrayConduitType.SetParameter(parameter, ElementId.InvalidElementId);
- }
- }
- }
- /// <summary>
- /// 获取桥架线管指定连接件的参数
- /// </summary>
- /// <param name="cableTrayConduitType"></param>
- /// <param name="parameter"></param>
- /// <returns></returns>
- public static ElementId GetFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter)
- {
- ElementId elmentId = null;
- if (cableTrayConduitType is ConduitType || cableTrayConduitType is CableTrayType)
- {
- if (null != cableTrayConduitType)
- {
- elmentId = cableTrayConduitType.GetParameterElementId(parameter);
- }
- }
- return elmentId;
- }
- #endregion
- }
- }
|