MbiExport.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:TestExport
  3. * 作者:xulisong
  4. * 创建时间: 2019/6/18 15:43:54
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using Autodesk.Revit.DB;
  11. using MBIRevitBase.Services;
  12. using MBIRevitBase.Tools;
  13. using Newtonsoft.Json;
  14. using RevitExport.Export;
  15. using RevitToJBim.ComponentParse;
  16. using RevitToJBim.JsonConverter;
  17. using RevitToJBim.MBI;
  18. using SAGA.DotNetUtils.Logger;
  19. using ServiceRevitLib.Mode;
  20. namespace RevitToJBim
  21. {
  22. public class MbiExport
  23. {
  24. public static string Export(Document document, string param)
  25. {
  26. string result = null;
  27. //导出类
  28. try
  29. {
  30. var wrappers = ExportDataBuilder.CreateExportData(document);
  31. ExportInstance report = new ExportInstance(wrappers);
  32. //解析类
  33. JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
  34. context.Parser.Parse(report);
  35. //构建需要结果
  36. var mbiDocument = MBIDocument.CreateDocument(document, param);
  37. mbiDocument.AttachElements(context.GetResultDocument());
  38. /*
  39. * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
  40. * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
  41. */
  42. var json = BimJsonUtil.Serializer(mbiDocument);
  43. //var json = File.ReadAllText(@"C:\Users\SAGACLOUD\Desktop\新建文件夹\88.rvt_20191220105510.json");
  44. #if DEBUG
  45. //保存到本地
  46. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  47. string path = Path.Combine($"{document.PathName}_{fileName}.json");
  48. File.WriteAllText(path, json.ToString());
  49. #endif
  50. Log4Net.Info("Begin UploadExportFile");
  51. var resultResponse = UploadService.UploadExportFile(json);
  52. result = BimJsonUtil.Serializer((ResultBase)resultResponse);
  53. Log4Net.Info("End UploadExportFile");
  54. }
  55. catch (Exception ex)
  56. {
  57. result = BimJsonUtil.Serializer(ResultBase.Exception(ex.Message + ex.StackTrace));
  58. }
  59. return result;
  60. }
  61. }
  62. }