123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- using Autodesk.Revit.DB;
- using Autodesk.Revit.DB.Mechanical;
- using Autodesk.Revit.DB.Plumbing;
- 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 PipeExtension
- {
- /// <summary>
- /// 获取较较大直径的管道
- /// </summary>
- /// <param name="first"></param>
- /// <param name="second"></param>
- /// <returns></returns>
- public static Pipe GetLargerDiameter(this Pipe first, Pipe second)
- {
- return first.Diameter.MoreEqual(second.Diameter)
- ? first
- : second;
- }
- /// <summary>
- /// 获取较较小直径的管道
- /// </summary>
- /// <param name="first"></param>
- /// <param name="second"></param>
- /// <returns></returns>
- public static Pipe GetSmallerDiameter(this Pipe first, Pipe second)
- {
- return first.Diameter.LessEqual(second.Diameter)
- ? first
- : second;
- }
- /// <summary>
- /// 获取管道系统分类
- /// </summary>
- /// <param name="pipe"></param>
- /// <returns></returns>
- public static PipeSystemType GetPipeSystemType(this Pipe pipe)
- {
- var pipingSystem = pipe.MEPSystem as PipingSystem;
- if (pipingSystem != null)
- return pipingSystem.SystemType;
- return PipeSystemType.UndefinedSystemType;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="pipe"></param>
- /// <returns></returns>Horizontal
- public static PipingSystemType GetPipingSystemType(this Pipe pipe)
- {
- var elementId = pipe.GetParameterElementId(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
- return pipe.Document.GetElement(elementId) as PipingSystemType;
- }
-
- public static List<XYZ> GetPoints(this Pipe pipe)
- {
- return new List<XYZ> { pipe.GetLocationLine().StartPoint(), pipe.GetLocationLine().EndPoint() };
- }
-
- /// <summary>
- /// 获取指定管道的管道系统
- /// </summary>
- /// <param name="pipe"></param>
- /// <returns></returns>
- public static PipingSystemType GePipingSystemType(this Pipe pipe)
- {
- return pipe.Document.GetElement(pipe.MEPSystem.GetTypeId()) as PipingSystemType;
- }
- /// <summary>
- /// 获取横向管道系统,处于同一直线的一系列管道
- /// </summary>
- /// <param name="pipe">指定管道</param>
- /// <returns></returns>
- public static List<Pipe> GetSystemPipe(this Pipe pipe)
- {
- List<Pipe> pipes = new List<Pipe>();
- do
- {
- //if (pipe == null)
- //{
- // break;
- //}
- //Line baseLine = pipe.GetLocationLine();
- //pipes.Add(pipe);
- //for (int i = 0; i < pipes.Count; i++)
- //{
- // Pipe tempPipe = pipes[i];
- // List<Element> verPipes = tempPipe.GetFirstSameTypeElements();
- // foreach (var element in verPipes)
- // {
- // Pipe tempVerPipe = element as Pipe;
- // if (tempVerPipe != null && tempVerPipe.GetCurveExt().IsParallel(baseLine, 0.001) &&
- // pipes.All(e => e.Id.IntegerValue != tempVerPipe.Id.IntegerValue))
- // {
- // pipes.Add(tempVerPipe);
- // }
- // }
- //}
- } while (false);
- return pipes;
- }
- /// <summary>
- /// 判断管道系统是否为坡度管
- /// </summary>
- /// <param name="pipes"></param>
- /// <returns></returns>
- public static bool IsSlopPipe(this List<Pipe> pipes)
- {
- if (pipes == null || pipes.Count == 0)
- return false;
- double baseZ = pipes[0].GetPoints()[0].Z;
- foreach (var pipe in pipes)
- {
- List<XYZ> ends = pipe.GetPoints();
- if (ends.Any(xyz => !xyz.Z.IsEqual(baseZ)))
- {
- return false;
- }
- }
- return true;
- }
- /// <summary>
- /// 设置管道直径
- /// </summary>
- /// <param name="pipe"></param>
- /// <param name="dia">直径</param>
- public static void SetDiameter(this Pipe pipe, double dia)
- {
- pipe.SetParameter(BuiltInParameter.RBS_PIPE_DIAMETER_PARAM, dia); //直径
- }
-
- /// <summary>
- /// 获取管道的管材
- /// </summary>
- /// <param name="pipe"></param>
- public static string GetMaterial(this Pipe pipe)
- {
- string material = pipe.GetParameterString(BuiltInParameter.RBS_PIPE_MATERIAL_PARAM);
- return material;
- }
- /// <summary>
- /// 是否是相同的系统
- /// </summary>
- /// <param name="pipe"></param>
- /// <param name="element"></param>
- /// <returns></returns>
- public static bool IsSameSystem(this Pipe pipe, Element element)
- {
- var elementId = pipe.GetParameterElementId(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
- if (elementId == null)
- return false;
- var refElementId = element.GetParameterElementId(BuiltInParameter.RBS_PIPING_SYSTEM_TYPE_PARAM);
- if (refElementId == null)
- return false;
- if (elementId.IntegerValue == -1 || refElementId.IntegerValue == -1)
- return false;
- return elementId == refElementId;
- }
- /// <summary>
- /// 获取坡度设置
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<double> GetSlopes(this Document doc)
- {
- List<double> slopes = new List<double>();
- PipeSettings setting = PipeSettings.GetPipeSettings(doc);
- if (setting != null)
- {
- slopes = setting.GetPipeSlopes().ToList();
- }
- return slopes;
- }
- /// <summary>
- /// 获取项目中所有管道类型
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<PipeType> GetPipeTypes(this Document doc)
- {
- List<PipeType> list = doc.GetElements<PipeType>();
- return list;
- }
- /// <summary>
- /// 获取管道类型的 管段 信息
- /// </summary>
- /// <param name="pipeType">管道类型</param>
- /// <param name="doc">所在项目</param>
- /// <returns></returns>
- public static PipeSegment GetPipeSegment(this PipeType pipeType, Document doc)
- {
- PipeSegment pipeSegment = null;
- RoutingPreferenceRule rule =
- pipeType.RoutingPreferenceManager.GetRule(RoutingPreferenceRuleGroupType.Segments, 0);
- if (rule == null)
- return pipeSegment;
- pipeSegment = doc.GetElement(rule.MEPPartId) as PipeSegment;
- return pipeSegment;
- }
- /// <summary>
- /// 增加管道的管段信息
- /// </summary>
- /// <param name="pipeType">管道类型</param>
- /// <param name="segmentId">管段Id</param>
- /// <returns></returns>
- public static int AddPipeSegment(this PipeType pipeType, ElementId segmentId)
- {
- return pipeType.AddRoutingRule(RoutingPreferenceRuleGroupType.Segments, segmentId, 0);
- }
- /// <summary>
- /// 移除管段类型
- /// </summary>
- /// <param name="pipeType"></param>
- /// <param name="index"></param>
- /// <returns></returns>
- public static int RemovePipeSegment(this PipeType pipeType, int index)
- {
- return pipeType.RemoveRoutingRule(RoutingPreferenceRuleGroupType.Segments, index);
- }
- /// <summary>
- /// 获取管道类型的可用直径信息
- /// </summary>
- /// <param name="pipeType">管道类型</param>
- /// <param name="doc">所在项目</param>
- /// <returns></returns>
- public static List<double> GetAvailableDias(this PipeType pipeType, Document doc)
- {
- PipeSegment pipeSegment = pipeType.GetPipeSegment(doc);
- List<double> dias = new List<double>();
- if (pipeSegment != null)
- {
- dias = pipeSegment.GetSizes().Select(mepSize => mepSize.NominalDiameter.MmFromFt()).ToList();
- }
- return dias;
- }
- #region 管道类型规则操作基础
- /// <summary>
- /// 增加管道优先规则
- /// </summary>
- /// <param name="pipeType">管道类型</param>
- /// <param name="groupType">规则分组</param>
- /// <param name="elementId">规则使用的element</param>
- /// <param name="index">规则在分组中的位置</param>
- /// <returns></returns>
- public static int AddRoutingRule(this PipeType pipeType, RoutingPreferenceRuleGroupType groupType,
- ElementId elementId, int index = 0)
- {
- RoutingPreferenceManager manager = pipeType.RoutingPreferenceManager;
- RoutingPreferenceRule rule = new RoutingPreferenceRule(elementId, "");
- rule.AddCriterion(PrimarySizeCriterion.All());
- manager.AddRule(groupType, rule, 0);
- return index;
- }
- /// <summary>
- /// 移除管道规则分组中制定位置的规则
- /// </summary>
- /// <param name="pipeType">管道类型</param>
- /// <param name="groupType">规则分组</param>
- /// <param name="index">规则在该分组中的位置</param>
- /// <returns></returns>
- public static int RemoveRoutingRule(this PipeType pipeType, RoutingPreferenceRuleGroupType groupType,
- int index = 0)
- {
- RoutingPreferenceManager manager = pipeType.RoutingPreferenceManager;
- manager.RemoveRule(groupType, index);
- return index;
- }
- /// <summary>
- /// 获取管道优先规则分组中指定位置的规则
- /// </summary>
- /// <param name="pipeType"></param>
- /// <param name="groupType"></param>
- /// <param name="index"></param>
- /// <returns></returns>
- public static RoutingPreferenceRule GetRoutingRule(this PipeType pipeType,
- RoutingPreferenceRuleGroupType groupType, int index = 0)
- {
- RoutingPreferenceRule rule = pipeType.RoutingPreferenceManager.GetRule(groupType, index);
- return rule;
- }
- public static ElementId GetRoutingRule(this PipeType pipeType, RoutingPreferenceRuleGroupType groupType,
- double nd)
- {
- RoutingConditions conditions = new RoutingConditions(RoutingPreferenceErrorLevel.None);
- conditions.AppendCondition(new RoutingCondition(nd));
- ElementId id = pipeType.RoutingPreferenceManager.GetMEPPartId(groupType,
- conditions);
- return id;
- }
- #endregion
- #region 动态修改连接件辅助使用方法
- /// <summary>
- /// 在三通规则分组第一个位置添加制定类型三通
- /// </summary>
- /// <param name="pipeType"></param>
- /// <param name="id"></param>
- /// <returns></returns>
- public static int AddFirstTee(this PipeType pipeType, ElementId id)
- {
- return pipeType.AddRoutingRule(RoutingPreferenceRuleGroupType.Junctions, id, 0);
- }
- /// <summary>
- /// 移除三通规则分组第一个位置的三通
- /// </summary>
- /// <param name="pipeType"></param>
- public static void RemoveFirstTee(this PipeType pipeType)
- {
- pipeType.RemoveRoutingRule(RoutingPreferenceRuleGroupType.Junctions);
- }
- /// <summary>
- /// 获取第一个三通
- /// </summary>
- /// <param name="pipeType"></param>
- /// <returns></returns>
- public static FamilySymbol GetFirstTee(this PipeType pipeType)
- {
- Document doc = pipeType.Document;
- FamilySymbol fitting = null;
- RoutingPreferenceRule rule = pipeType.GetRoutingRule(RoutingPreferenceRuleGroupType.Junctions);
- if (rule == null)
- return fitting;
- fitting = doc.GetElement(rule.MEPPartId) as FamilySymbol;
- return fitting;
- }
- /// <summary>
- /// 通过直径获取指定规则的三通,如果指定直径不存在对应三通,则默认去第一个设定的三通
- /// </summary>
- /// <param name="pipeType">管道类型</param>
- /// <param name="nd">直径</param>
- /// <returns></returns>
- public static FamilySymbol GetFirstTeeByNd(this PipeType pipeType, double nd)
- {
- Document doc = pipeType.Document;
- FamilySymbol fitting = null;
- ElementId elementId = pipeType.GetRoutingRule(RoutingPreferenceRuleGroupType.Junctions, nd);
- if (elementId == null)
- {
- RoutingPreferenceRule rule = pipeType.GetRoutingRule(RoutingPreferenceRuleGroupType.Junctions);
- if (rule == null)
- return fitting;
- elementId = rule.MEPPartId;
- }
- fitting = doc.GetElement(elementId) as FamilySymbol;
- return fitting;
- }
- #endregion
-
- }
- }
|