12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- /*-------------------------------------------------------------------------
- * 功能描述:TestExport
- * 作者:xulisong
- * 创建时间: 2019/6/18 15:43:54
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.IO;
- using Autodesk.Revit.DB;
- using MBIRevitBase.Services;
- using MBIRevitBase.Tools;
- using Newtonsoft.Json;
- using RevitExport.Export;
- using RevitToJBim.ComponentParse;
- using RevitToJBim.JsonConverter;
- using RevitToJBim.MBI;
- using SAGA.DotNetUtils.Logger;
- using ServiceRevitLib.Mode;
- namespace RevitToJBim
- {
- public class MbiExport
- {
- public static string Export(Document document, string param)
- {
- string result = null;
- //导出类
- try
- {
- var wrappers = ExportDataBuilder.CreateExportData(document);
- ExportInstance report = new ExportInstance(wrappers);
- //解析类
- JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
- context.Parser.Parse(report);
- //构建需要结果
- var mbiDocument = MBIDocument.CreateDocument(document, param);
- mbiDocument.AttachElements(context.GetResultDocument());
- /*
- * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
- * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
- */
- var json = BimJsonUtil.Serializer(mbiDocument);
- //var json = File.ReadAllText(@"C:\Users\SAGACLOUD\Desktop\新建文件夹\88.rvt_20191220105510.json");
- #if DEBUG
- //保存到本地
- string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
- string path = Path.Combine($"{document.PathName}_{fileName}.json");
- File.WriteAllText(path, json.ToString());
- #endif
- Log4Net.Info("Begin UploadExportFile");
- var resultResponse = UploadService.UploadExportFile(json);
- result = BimJsonUtil.Serializer((ResultBase)resultResponse);
- Log4Net.Info("End UploadExportFile");
- }
- catch (Exception ex)
- {
- result = BimJsonUtil.Serializer(ResultBase.Exception(ex.Message + ex.StackTrace));
- }
- return result;
- }
- }
- }
|