MbiExport.cs 2.3 KB

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