|
@@ -0,0 +1,121 @@
|
|
|
+/* ==============================================================================
|
|
|
+ * 功能描述:ReuploadBaseMap
|
|
|
+ * 创 建 者:Garrett
|
|
|
+ * 创建日期:2019/10/9 20:19:06
|
|
|
+ * ==============================================================================*/
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Autodesk.Revit.DB;
|
|
|
+using SAGA.DotNetUtils.Extend;
|
|
|
+using SAGA.MBI.Calc;
|
|
|
+using SAGA.MBI.Interaction;
|
|
|
+using SAGA.MBI.RevitExport;
|
|
|
+using SAGA.MBI.Tools;
|
|
|
+using SAGA.MBI.WinView.Upload;
|
|
|
+using SAGA.RevitUtils;
|
|
|
+using SAGA.RevitUtils.Extends;
|
|
|
+
|
|
|
+namespace SAGA.MBI.Test
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// ReuploadBaseMap
|
|
|
+ /// </summary>
|
|
|
+ class ReuploadBaseMap
|
|
|
+ {
|
|
|
+ public static void Execute()
|
|
|
+ {
|
|
|
+ WinSelectFileFloder win = new WinSelectFileFloder();
|
|
|
+ if (win.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ Operate(win.RevitDirs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private static void Operate(string revitDir)
|
|
|
+ {
|
|
|
+ var list = GetRevitFiles(revitDir);
|
|
|
+ if (!list.Any()) return;
|
|
|
+ foreach (string fullPath in list)
|
|
|
+ {
|
|
|
+ OperateFloor(fullPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void OperateFloor(string fullPath)
|
|
|
+ {
|
|
|
+ Document doc = null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var uiApp = ExternalDataWrapper.Current.UiApp;
|
|
|
+ ModelPath mpath=new FilePath(fullPath);
|
|
|
+ OpenOptions options=new OpenOptions();
|
|
|
+ options.AllowOpeningLocalByWrongUser = true;
|
|
|
+ doc = uiApp.Application.OpenDocumentFile(mpath,options);
|
|
|
+ MbiElementManager.ExecuteExport(doc);
|
|
|
+
|
|
|
+ var floorId = GetFloorId(fullPath);
|
|
|
+
|
|
|
+ string sagaName = doc.GetUseView()?.Name;
|
|
|
+ var result=MBIModelInfoUpload.GetCompressedExportInfo(sagaName);
|
|
|
+
|
|
|
+ string key = $"{floorId}" + DateTime.Now.ToString("yyyyMMddHHmmss") + "bim.jsonz";//楼层对应信息文件key值
|
|
|
+ File.WriteAllBytes(Path.Combine(GetDirectory(fullPath),key),result);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ var dir = GetDirectory(fullPath);
|
|
|
+ string errorPath = Path.Combine(dir, "ErrorFiles");
|
|
|
+ if (!Directory.Exists(errorPath))
|
|
|
+ Directory.CreateDirectory(errorPath);
|
|
|
+ File.Copy(fullPath,errorPath);
|
|
|
+ string errorLog = Path.Combine(errorPath, "errorLog.txt");
|
|
|
+ File.AppendAllText(errorLog,$"{DateTime.Now.TimeOfDay} | {fullPath} | {e.Message} | {e.StackTrace}");
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ doc?.CloseDocSimple();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static string GetFloorId(string fullPath)
|
|
|
+ {
|
|
|
+ var fileName = fullPath.GetFileName();
|
|
|
+ var strs = fileName.Split('_');
|
|
|
+ string floorId = fileName;
|
|
|
+ if (strs.Length == 3)
|
|
|
+ floorId = strs[2];
|
|
|
+ return floorId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static string GetDirectory(string fullPath)
|
|
|
+ {
|
|
|
+ FileInfo fileInfo = new FileInfo(fullPath);
|
|
|
+ var dir = fileInfo.DirectoryName;
|
|
|
+ return dir;
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// 获取需要修改的Revit文件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="revitDir"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ private static List<string> GetRevitFiles(string revitDir)
|
|
|
+ {
|
|
|
+ DirectoryInfo directory = new DirectoryInfo(revitDir);
|
|
|
+ List<string> list = new List<string>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ list = directory.GetFiles("*.rvt").Where(t => !t.FullName.Is000File()).Select(t => t.FullName).ToList();
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ Console.WriteLine(e);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|