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 水管风管类型布线规则维护
///
/// 增加MepCurve优先规则
///
/// MepCurve类型
/// 规则分组
/// 规则使用的element
/// 规则在分组中的位置
/// -1操作类型不符
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;
}
}
///
/// 移除MepCurve规则分组中制定位置的规则
///
/// MepCurve类型
/// 规则分组
/// 规则在该分组中的位置
/// -1操作类型不符
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;
}
///
/// 获取MepCurve优先规则分组中指定位置的规则
///
///
///
///
///
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 线管桥架连接件类型维护
///
/// 修改桥架线管指定连接件的参数
///
/// 桥架线管
/// 连接件类型参数
/// 规则使用的element
///
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);
}
}
}
///
/// 移除桥架线管指定连接件的参数
///
/// 桥架线管
/// 连接件类型参数
///
public static void RemoveFitting(this MEPCurveType cableTrayConduitType, BuiltInParameter parameter)
{
if (cableTrayConduitType is ConduitType || cableTrayConduitType is CableTrayType)
{
if (null != cableTrayConduitType)
{
cableTrayConduitType.SetParameter(parameter, ElementId.InvalidElementId);
}
}
}
///
/// 获取桥架线管指定连接件的参数
///
///
///
///
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
}
}