MbiExport.cs 1.8 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 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. var wrappers = ExportDataBuilder.CreateExportData(document);
  33. ExportInstance report = new ExportInstance(wrappers);
  34. //解析类
  35. JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
  36. context.Parser.Parse(report);
  37. //构建需要结果
  38. var mbiDocument = MBIDocument.CreateDocument(document);
  39. mbiDocument.AttachElements(context.GetResultDocument());
  40. /*
  41. * 序列化的变化封装在这里,增加MBIDocument传输数据对象,
  42. * 增加一些和JBIM无关,又和当前业务逻辑相关的属性
  43. */
  44. var result = BimJsonUtil.Serializer(mbiDocument);
  45. string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
  46. string path = Path.Combine(@"D:\", $"{fileName}.json");
  47. File.WriteAllText(path, result);
  48. System.Diagnostics.Process.Start("notepad.exe", path);
  49. }
  50. }
  51. }