123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- 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
- { /// <summary>
- /// 获取水管和风管保温层
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<ElementType> 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<ElementType> types = doc.GetElementTypes<ElementType>(filter);
- return types;
- }
- /// <summary>
- /// 获取水管的保温层
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<ElementType> GetPipeInsulationTypes(this Document doc)
- {
- List<ElementType> types = doc.GetElementTypes<ElementType>(new ElementCategoryFilter(BuiltInCategory.OST_PipeInsulations));
- return types;
- }
- /// <summary>
- /// 获取风管的保温层
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<ElementType> GetDuctInsulationTypes(this Document doc)
- {
- List<ElementType> types = doc.GetElementTypes<ElementType>(new ElementCategoryFilter(BuiltInCategory.OST_DuctInsulations));
- return types;
- }
- /// <summary>
- /// 获取管道和管道连接件的保温层
- /// </summary>
- /// <param name="doc"></param>
- /// <returns></returns>
- public static List<InsulationLiningBase> GetPipeInsulations(this Document doc)
- {
- List<InsulationLiningBase> elements =
- doc.GetElements<InsulationLiningBase>().Where(
- el =>
- el.GetBuiltInCategory() == BuiltInCategory.OST_PipeInsulations ||
- el.GetBuiltInCategory() == BuiltInCategory.OST_PipeFittingInsulation).ToList();
- return elements.Where(e => e.IsValidObject).ToList();
- }
- /// <summary>
- /// 创建保温层
- /// </summary>
- /// <param name="element"></param>
- /// <param name="info"></param>
- 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);
- }
- }
- /// <summary>
- /// 删除保温层
- /// </summary>
- /// <param name="elements"></param>
- public static void DeleteInsulations(this List<Element> 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);
- }
- }
- /// <summary>
- /// 获取指定管道集合中的第一个保温层信息
- /// </summary>
- /// <param name="elements">elements尽可能只包含水系统或者风系统</param>
- /// <returns></returns>
- public static InsulationItem GetInsulationItem(this List<Element> elements)
- {
- InsulationItem info = null;
- List<ElementType> pipeInsulation = null;
- List<ElementType> 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;
- }
- }
- /// <summary>
- /// 保温层包装类
- /// </summary>
- public class InsulationItem
- {
- public ElementType InsulationType { get; set; }
- public double Thickness { get; set; }
- }
- }
|