MbiExport.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 RevitExport.Export;
  14. using RevitToJBim.ComponentParse;
  15. using RevitToJBim.JsonConverter;
  16. using RevitToJBim.MBI;
  17. namespace RevitToJBim
  18. {
  19. public class MbiExport
  20. {
  21. public static void Export(Document document)
  22. {
  23. //导出类
  24. try
  25. {
  26. var wrappers = ExportDataBuilder.CreateExportData(document);
  27. ExportInstance report = new ExportInstance(wrappers);
  28. //解析类
  29. JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
  30. context.Parser.Parse(report);
  31. //构建需要结果
  32. var mbiDocument = MBIDocument.CreateDocument(document);
  33. mbiDocument.AttachElements(context.GetResultDocument());
  34. /*
  35. * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
  36. * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
  37. */
  38. var result = BimJsonUtil.Serializer(mbiDocument);
  39. var resultResponse = UploadService.UploadExportFile(result);
  40. //string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  41. //string path = Path.Combine(@"D:\", $"{fileName}.json");
  42. //File.WriteAllText(path, resultResponse.ToString());
  43. //System.Diagnostics.Process.Start("notepad.exe", path);
  44. }
  45. catch (Exception ex)
  46. {
  47. Console.WriteLine(ex.StackTrace.ToString());
  48. }
  49. }
  50. }
  51. }