/*------------------------------------------------------------------------- * 功能描述:TestExport * 作者:xulisong * 创建时间: 2019/6/18 15:43:54 * 版本号:v1.0 * -------------------------------------------------------------------------*/ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Mechanical; using Autodesk.Revit.DB.Plumbing; using Autodesk.Revit.UI; using MBIRevitBase.Tools; using RevitExport; using RevitExport.Export; using RevitToJBim.ComponentParse; using RevitToJBim.JsonConverter; using RevitToJBim.MBI; using SAGA.RevitUtils; using SAGA.RevitUtils.Extends; namespace RevitToJBim { public class MbiExport { public static void Export(Document document) { //导出类 try { var wrappers = ExportDataBuilder.CreateExportData(document); ExportInstance report = new ExportInstance(wrappers); //解析类 JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers()); context.Parser.Parse(report); //构建需要结果 var mbiDocument = MBIDocument.CreateDocument(document); mbiDocument.AttachElements(context.GetResultDocument()); /* * 序列化的变化封装在这里,增加MBIDocument传输数据对象, * 增加一些和JBIM无关,又和当前业务逻辑相关的属性 */ var result = BimJsonUtil.Serializer(mbiDocument); var stream = ZipUtils.ZipString(result,"export.json"); var resultResponse=HttpUtils.PostFormDataFile("http://192.168.20.225:8080/revit-algorithm/upload-json-zip/upload", stream); string fileName = DateTime.Now.ToString("yyyyMMddHHmmss"); string path = Path.Combine(@"D:\", $"{fileName}.json"); File.WriteAllText(path, resultResponse.ToString()); System.Diagnostics.Process.Start("notepad.exe", path); } catch (Exception ex) { Console.WriteLine(ex.StackTrace.ToString()); } } } }