using Autodesk.Revit.DB;
|
using Autodesk.Revit.DB.Electrical;
|
using Autodesk.Revit.DB.Mechanical;
|
using Autodesk.Revit.DB.Plumbing;
|
using Glodon.Revit.Utility;
|
using HStation.RevitDev.Model.ModelEnum;
|
using HStation.RevitDev.RevitDataExport.Common;
|
using HStation.RevitDev.RevitDataExport.Entity;
|
using HStation.RevitDev.RevitDataExport.Utility;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
using System.Linq;
|
|
namespace HStation.RevitDev.RevitDataExport.Service
|
{
|
public class RevitMepElementService
|
{
|
public static IEnumerable<Element> GetSubElements(MEPSystem system)
|
{
|
var elements = new List<Element>();
|
if (system is ElectricalSystem elecSystem)
|
{
|
|
}
|
else if (system is MechanicalSystem mechSystem)
|
{
|
|
}
|
else if (system is PipingSystem pipeSystem)
|
{
|
var network = pipeSystem.PipingNetwork;
|
foreach (Element subElem in network)
|
{
|
elements.Add(subElem);
|
}
|
}
|
else
|
{
|
|
}
|
return elements;
|
}
|
|
public static List<ElementId> GetSubElementIds(MEPSystem system)
|
{
|
var elements = GetSubElements(system);
|
var elemIds = elements.Select(x => x.Id).ToList();
|
return elemIds;
|
}
|
|
public static List<Element> GetSubElements(MEPSystemType systemType)
|
{
|
var systemIds = systemType.GetDependentElements(new ElementClassFilter(typeof(PipingSystem),false));
|
var elements = new List<Element>();
|
foreach (var systemId in systemIds)
|
{
|
var system = systemType.Document.GetElement(systemId) as PipingSystem;
|
if (system == null) { continue; }
|
elements.AddRange(GetSubElements(system));
|
}
|
return elements;
|
}
|
|
public static List<Element> GetSubElements(Document doc, string sysTypeName)
|
{
|
var pipingSystems = new FilteredElementCollector(doc)
|
.OfClass(typeof(MEPSystem))
|
.Where(x => x != null && x is PipingSystem && x.Id != ElementId.InvalidElementId && sysTypeName.Any(y => x.Name.Contains(y + " ")))
|
.OfType<PipingSystem>()
|
.ToList();
|
var elems = new List<Element>();
|
foreach (var system in pipingSystems)
|
{
|
if (system.PipingNetwork.Size > 0)
|
{
|
foreach (Element elem in system.PipingNetwork)
|
{
|
elems.Add(elem);
|
}
|
}
|
try
|
{
|
if (system.Elements.Size > 0)
|
{
|
foreach (Element elem in system.Elements)
|
{
|
if (elems.Any(x => x.Id.IntegerValue == elem.Id.IntegerValue))
|
{
|
continue;
|
}
|
elems.Add(elem);
|
}
|
}
|
}
|
catch (Exception)
|
{
|
continue;
|
}
|
}
|
return elems;
|
}
|
|
public static List<Element> GetElements(Document doc, string sysTypeName)
|
{
|
var elems = new List<Element>();
|
if (doc == null || string.IsNullOrEmpty(sysTypeName)) { return elems; }
|
|
elems = GetElementsByPipeSystemTypeName(doc, sysTypeName);
|
return elems;
|
}
|
|
private static List<Element> GetElementsByPipeSystemTypeName(Document doc, string sysTypeName)
|
{
|
var result = new List<Element>();
|
List<Element> instances = GetInstanceAndPipes(doc);
|
foreach (var instance in instances)
|
{
|
var id = instance.Id.IntegerValue;
|
if (id == 3396216)
|
{
|
|
}
|
var systemType = ParameterOperator.GetElementPipingSystemType(instance);
|
if (systemType != null && systemType.Name == sysTypeName)
|
{
|
result.Add(instance);
|
}
|
}
|
return result;
|
}
|
|
private static List<Element> FamilyInstanceAndPipesCache = null;
|
private static List<Element> GetInstanceAndPipes(Document doc)
|
{
|
if (FamilyInstanceAndPipesCache != null)
|
{
|
return FamilyInstanceAndPipesCache;
|
}
|
var cates = doc.Settings.Categories;
|
var itor = cates.GetEnumerator();
|
var categories = new List<Category>();
|
while (itor.MoveNext())
|
{
|
var cate = itor.Current as Category;
|
categories.Add(cate);
|
}
|
var types = new List<Type> { typeof(FamilyInstance), typeof(Pipe) };
|
var instances = ElementUtil.GetElements(types, isModel: true, categories: categories);
|
FamilyInstanceAndPipesCache = instances;
|
return instances;
|
}
|
|
public static List<string> GetElementModels(RevitType type)
|
{
|
List<string> ret = new List<string>();
|
if (!GlobalResource.RevitModels.ContainsKey(type)) { return ret; }
|
var doc = GlobalResource.CurrentDocument;
|
var dict = GlobalResource.RevitModels.Find(x=>x.Item1 == doc.Title)?.Item2;
|
if (dict == null) { return ret; }
|
|
return dict[type];
|
}
|
}
|
}
|