using Autodesk.Revit.DB; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Plumbing; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FWindSoft.Revit { public static class MepSystemTypeExtension { public static readonly ReadOnlyCollection DuctClassifications =new ReadOnlyCollection( new List { "SupplyAir", "ReturnAir", "ExhaustAir" }); public static readonly ReadOnlyCollection PipeClassifications = new ReadOnlyCollection(new List { "Sanitary", "Vent", "DomesticHotWater", "DomesticColdWater", "OtherPipe", "FireProtectWet", "FireProtectDry", "FireProtectPreaction", "FireProtectOther", "SupplyHydronic", "ReturnHydronic"}); /// /// 根据系统分类创建系统类型 /// /// 创建系统的指定项目 /// 系统分类 /// 系统名称 /// public static MEPSystemType MEPSystemTypeCreate(this Document doc, MEPSystemClassification classification,string name) { if (DuctClassifications.Contains(classification.ToString())) return MechanicalSystemType.Create(doc, classification, name); if (PipeClassifications.Contains(classification.ToString())) return PipingSystemType.Create(doc, classification, name); return null; } /// /// 或取全部管道系统(可指定相应的系统分类) /// /// /// /// public static List GetPipingSystemTypes(this Document doc, MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification) { ElementCategoryFilter pipeSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipingSystem); List list = doc.GetElements(); if (classification != MEPSystemClassification.UndefinedSystemClassification) { list = list.Where(s => s.SystemClassification == classification).ToList(); } return list; } /// /// 或取项目已经使用的管道系统(可指定相应的系统分类) /// /// /// /// public static List GetUsedPipingSystemTypes(this Document doc, MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification) { ElementCategoryFilter pipeSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_PipingSystem); var listIds = doc.GetElements().Select(p => p.GetTypeId()).Distinct(); List list = listIds.Select(id => doc.GetElement(id)).ToList(); List tempSystemType = list.OfType().ToList(); if (classification != MEPSystemClassification.UndefinedSystemClassification) { tempSystemType = tempSystemType.Where(s => s.SystemClassification == classification).ToList(); } return tempSystemType; } /// /// 或取全部风管系统类型(可指定相应的系统分类) /// /// /// /// public static List GetMechanicalSystemTypes(this Document doc, MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification) { ElementCategoryFilter ductSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_DuctSystem); List list = doc.GetElements(ductSystemFilter).OfType().ToList(); if (classification != MEPSystemClassification.UndefinedSystemClassification) { list = list.Where(s => s.SystemClassification == classification).ToList(); } return list; } /// /// 或取项目已经使用的风管系统系统(可指定相应的系统分类) /// /// /// /// public static List GetUsedMechanicalSystemTypes(this Document doc, MEPSystemClassification classification = MEPSystemClassification.UndefinedSystemClassification) { ElementCategoryFilter ductSystemFilter = new ElementCategoryFilter(BuiltInCategory.OST_DuctSystem); var listIds = doc.GetElements(ductSystemFilter).OfType() .Select(p => p.GetTypeId()) .Distinct(); List list = listIds.Select(id => doc.GetElement(id)).ToList(); List tempSystemType = list.OfType().ToList(); if (classification != MEPSystemClassification.UndefinedSystemClassification) { tempSystemType = tempSystemType.Where(s => s.SystemClassification == classification).ToList(); } return tempSystemType; } } }