using Autodesk.Revit.DB; using HStation.RevitDev.Model.AttributeClass; using HStation.RevitDev.Model.ModelEnum; using HStation.RevitDev.RevitDataExport.Common; using HStation.RevitDev.RevitDataExport.Entity; using HStation.RevitDev.RevitDataExport.Entity.ElementModels; using HStation.RevitDev.RevitDataExport.Parser; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Reflection; namespace HStation.RevitDev.RevitDataExport.Utility { internal class ModelFactory { public ModelFactory() { } public static ElementModel CreateModel(RevitType revitType, Element element) { BaseParser parser = revitType.CreateModelParser(); var ret = new ElementModel(); if (parser == null) { return ret; } ret = parser.Parse(element); return ret; } public static List Convert2Sub(List ids) where T : ElementModel { var ret = new List(); foreach (var id in ids) { var elem = GlobalResource.CurrentDocument.GetElement(new ElementId(int.Parse(id))); if (elem == null) { continue; } var attr = typeof(T).GetCustomAttribute(); if (attr == null) { continue; } var parser = attr.m_revitType.GetParser(); if (parser == null) { continue; } T model = parser.Parse(elem) as T; ret.Add(model); } return ret; } public static List Convert2Others(List ids) { var ret = new List(); foreach (var id in ids) { var elem = GlobalResource.CurrentDocument.GetElement(new ElementId(int.Parse(id))); if (elem == null) { continue; } var parser = new QitaParser(); OtherModel model = parser.Parse(elem) as OtherModel; ret.Add(model); } return ret; } } }