12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /*-------------------------------------------------------------------------
- * 功能描述:ParseCore
- * 作者:xulisong
- * 创建时间: 2019/6/13 18:03:03
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using Autodesk.Revit.DB;
- using JBIM;
- using JBIM.Component;
- using RevitExport;
- using RevitToJBim.Common;
- using Connector = JBIM.Component.Connector;
- namespace RevitToJBim.ComponentParse
- {
- /*
- * 核心解析类不解析关系
- */
- /// <summary>
- /// 核心解析类
- /// </summary>
- public class ParseCore
- {
- //获取可用的解析类
- public static List<ParseBase> GetUseParsers()
- {
- List<ParseBase> result = new List<ParseBase>();
- Assembly assembly = Assembly.GetCallingAssembly();
- Type[] types = assembly.GetTypes();
- foreach (var type in types)
- {
- if (typeof(ParseBase).IsAssignableFrom (type))
- {
- if (type.IsAbstract || type.IsGenericTypeDefinition)
- continue;
- var attribute = type.GetCustomAttribute<UsableParseAttribute>();
- if (attribute == null)
- continue;
- var construstor = type.GetConstructor(Type.EmptyTypes);
- if (construstor == null)
- continue;
- if (construstor.Invoke(null) is ParseBase parse)
- result.Add(parse);
- }
- }
- return result;
- }
-
- public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
- {
- bimObj.SourceId = wrapper.SourceId;
- bimObj.Name = wrapper.RefElement?.Name;
- }
- public static Connector CreateConnector(Autodesk.Revit.DB.Connector connector)
- {
- var result= new Connector();
- result.SourceId = RevitIdGenerator.GetConnectorId(connector);
- switch (connector.Domain)
- {
- case Domain.DomainHvac:
- {
- result.Domain = ConnectorDomain.DomainHvac.ToString();
- break;
- }
- case Domain.DomainPiping:
- {
- result.Domain = ConnectorDomain.DomainPiping.ToString();
- break;
- }
- }
- result.IsConnected = connector.IsConnected;
- result.Description = connector.Description;
- result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
- return result;
- }
- /// <summary>
- /// 获取Connector包装类
- /// </summary>
- /// <param name="connector"></param>
- /// <returns></returns>
- public static ElementWrapper GetConnectorWrapper(Autodesk.Revit.DB.Connector connector)
- {
- ElementWrapper wrapper = new ElementWrapper(connector, RevitIdGenerator.GetConnectorId(connector));
- return wrapper;
- }
- }
- }
|