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.Extension { public static class InsulationExtension { /// /// 获取水管和风管保温层 /// /// /// public static List GetInsulationTypes(this Document doc) { ElementFilter pipe = new ElementCategoryFilter(BuiltInCategory.OST_PipeInsulations); ElementFilter duct = new ElementCategoryFilter(BuiltInCategory.OST_DuctInsulations); LogicalOrFilter filter = new LogicalOrFilter(pipe, duct); List types = doc.GetElementTypes(filter); return types; } /// /// 获取水管的保温层 /// /// /// public static List GetPipeInsulationTypes(this Document doc) { List types = doc.GetElementTypes(new ElementCategoryFilter(BuiltInCategory.OST_PipeInsulations)); return types; } /// /// 获取风管的保温层 /// /// /// public static List GetDuctInsulationTypes(this Document doc) { List types = doc.GetElementTypes(new ElementCategoryFilter(BuiltInCategory.OST_DuctInsulations)); return types; } /// /// 获取管道和管道连接件的保温层 /// /// /// public static List GetPipeInsulations(this Document doc) { List elements = doc.GetElements().Where( el => el.GetBuiltInCategory() == BuiltInCategory.OST_PipeInsulations || el.GetBuiltInCategory() == BuiltInCategory.OST_PipeFittingInsulation).ToList(); return elements.Where(e => e.IsValidObject).ToList(); } /// /// 创建保温层 /// /// /// public static void CreateInsulation(this Element element, InsulationItem info) { if (!element.IsValidObject) return; if (info == null || info.InsulationType == null) return; Document doc = element.Document; if (element.IsWaterComponment()) { var ids = InsulationLiningBase.GetInsulationIds(doc, element.Id); doc.Delete(ids); PipeInsulation.Create(doc, element.Id, info.InsulationType.Id, info.Thickness); } else if (element.IsHavcComponment()) { var ids = InsulationLiningBase.GetInsulationIds(doc, element.Id); doc.Delete(ids); DuctInsulation.Create(doc, element.Id, info.InsulationType.Id, info.Thickness); } } /// /// 删除保温层 /// /// public static void DeleteInsulations(this List elements) { var list = elements; if (list == null || list.Count == 0) return; Document doc = elements[0].Document; for (int i = 0; i < list.Count; i++) { Element temp = list[i]; if (!temp.IsValidObject) continue; bool isValid = temp.IsWaterComponment() || temp.IsHavcComponment(); if (!isValid) continue; var ids = InsulationLiningBase.GetInsulationIds(doc, temp.Id); doc.Delete(ids); } } /// /// 获取指定管道集合中的第一个保温层信息 /// /// elements尽可能只包含水系统或者风系统 /// public static InsulationItem GetInsulationItem(this List elements) { InsulationItem info = null; List pipeInsulation = null; List ductInsulation = null; do { if (elements == null || elements.Count == 0) { break; } Document doc = elements[0].Document; foreach (var element in elements) { if (element == null) continue; string name = element.GetParameterString(BuiltInParameter.RBS_REFERENCE_INSULATION_TYPE); double thick = element.GetParameterDouble(BuiltInParameter.RBS_REFERENCE_INSULATION_THICKNESS); if (!string.IsNullOrWhiteSpace(name) && thick.More(0)) { ElementType tempType = null; if (element.IsWaterComponment()) { if (pipeInsulation == null) { pipeInsulation = doc.GetPipeInsulationTypes(); } tempType = pipeInsulation.FirstOrDefault(t => t.Name.Equals(name)); } else if (element.IsHavcComponment()) { if (ductInsulation == null) { ductInsulation = doc.GetDuctInsulationTypes(); } tempType = ductInsulation.FirstOrDefault(t => t.Name.Equals(name)); } if (null != tempType) { info = new InsulationItem { InsulationType = tempType, Thickness = thick }; break; } } } } while (false); return info; } } /// /// 保温层包装类 /// public class InsulationItem { public ElementType InsulationType { get; set; } public double Thickness { get; set; } } }