MbiExport.cs 2.1 KB

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