Program.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using SAGA.DotNetUtils.Revit;
  2. using System;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using Newtonsoft.Json.Linq;
  6. using SAGA.DotNetUtils.Extend;
  7. namespace StartVisionSelector
  8. {
  9. public class Program
  10. {
  11. public static void Main(string[] args)
  12. {
  13. string command = null;
  14. string param = null;
  15. string path = null;
  16. if (args.Length > 0)
  17. {
  18. command = args[0];
  19. }
  20. if (args.Length > 1)
  21. {
  22. //注意,这个Replace很重要,不能缺少,
  23. param = args[1].Replace("\"", "\\\""); ;
  24. }
  25. if (args.Length > 2)
  26. {
  27. path = args[2];
  28. }
  29. #if DEBUG
  30. if (string.IsNullOrWhiteSpace(command))
  31. {
  32. command = "DataExport";
  33. path = @"E:\导出测试\testR17.rvt";
  34. path = @"E:\导出测试\TestEmptyR17.rvt";
  35. JObject jObject = new JObject();
  36. jObject.Add("ResultFileName", @"C:\Users\SAGACLOUD\AppData\Local\RevitService\Result_e26be2fd-2097-462b-bdd0-a2a86b616928.txt");
  37. param = jObject.ToString().Replace("\"","\\\"");
  38. //JObject jObject = new JObject();
  39. //jObject.Add("ResultFileName", @"D:\abc.txt");
  40. //param = jObject.ToString();
  41. //path= @"E:\导出测试\延庆园-B1.rvt";
  42. //path = @"E:\导出测试\testR18.rvt";
  43. //path = @"E:\导出测试\testR16.rvt";
  44. }
  45. #endif
  46. Console.WriteLine("start");
  47. #region 保存版本号
  48. //保存版本号
  49. var runPath = AppDomain.CurrentDomain.BaseDirectory;
  50. var revitVision = RevitVisionUtil.GetRevitVision(path);
  51. File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SelectorConst.RevitFileVisionFile), revitVision);
  52. #endregion
  53. #region 删除生成的Revit dll
  54. var loadingRevitPath = Path.Combine(runPath, SelectorConst.LoadingRevit);
  55. //先删除,后Copy,如果可以指定Revit的安装目录,不需要Copy
  56. #region Del RevitDll
  57. foreach (string loadingItem in File.ReadAllLines(loadingRevitPath))
  58. {
  59. string destFile = Path.Combine(runPath, $"{loadingItem}.dll");
  60. if(File.Exists(destFile))
  61. File.Delete(destFile);
  62. }
  63. #endregion
  64. #endregion
  65. #region 启动
  66. Process process = new Process();//AppDomain.CurrentDomain.BaseDirectory +
  67. process.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportStart.exe");//执行的exe路径
  68. process.StartInfo.UseShellExecute = false;//不显示shell
  69. process.StartInfo.CreateNoWindow = true;//不创建窗口
  70. process.StartInfo.RedirectStandardInput = true;//打开流输入
  71. process.StartInfo.RedirectStandardOutput = true;//打开流输出
  72. process.StartInfo.RedirectStandardError = true;//打开错误流
  73. process.StartInfo.Arguments = command + " "+
  74. "\"" + param + "\"" + " "+
  75. "\"" + path + "\"";//输入参数,多个参数使用空间分割,如果一个参数包含空格,使用""包括此参数
  76. process.Start();//执行
  77. string msg = process.StandardOutput.ReadToEnd();//读取输出
  78. Console.WriteLine(msg);
  79. process.WaitForExit();//等待执行完成
  80. process.Close();//结束
  81. #endregion
  82. Console.WriteLine("end");
  83. //Console.ReadKey();
  84. }
  85. }
  86. }