Program.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using Autodesk.Revit.DB;
  9. using Autodesk.Revit.DB.Mechanical;
  10. using Autodesk.RevitAddIns;
  11. using ServiceRevitLib;
  12. //using RevitToJBim.Common;
  13. namespace ExportStart
  14. {
  15. class Program
  16. {
  17. static Program()
  18. {
  19. RevitCoreContext.Instance.Run();
  20. }
  21. [STAThread]
  22. static void Main(string[] args)
  23. {
  24. string command = null;
  25. string path = null;
  26. if (args.Length > 0)
  27. {
  28. command = args[0];
  29. }
  30. if (args.Length > 1)
  31. {
  32. path = args[1];
  33. }
  34. #if DEBUG
  35. if (string.IsNullOrWhiteSpace(command))
  36. {
  37. command = "DataExport";
  38. path = @"E:\导出测试\test.rvt";
  39. }
  40. #endif
  41. if (string.IsNullOrEmpty(command))
  42. {
  43. Console.WriteLine("命令参数错误");
  44. }
  45. Console.WriteLine(command);
  46. Console.WriteLine(path);
  47. if (File.Exists(path)&&Enum.TryParse(command, out CommandType commandType))
  48. {
  49. var app = RevitCoreContext.Instance.Application;
  50. var doc = app.OpenDocumentFile(path);
  51. switch (commandType)
  52. {
  53. case CommandType.DataCheck:
  54. Check(doc);
  55. break;
  56. case CommandType.DataExport:
  57. Export(doc);
  58. break;
  59. }
  60. RevitCoreContext.Instance.Stop();
  61. }
  62. }
  63. enum CommandType
  64. {
  65. None = 0,
  66. DataCheck,
  67. DataExport
  68. }
  69. public static void Export(Document doc)
  70. {
  71. try
  72. {
  73. Console.WriteLine("Start Export");
  74. RevitToJBim.MbiExport.Export(doc);
  75. Console.WriteLine("End Export");
  76. }
  77. catch (Exception e)
  78. {
  79. Console.WriteLine("导出失败");
  80. Console.WriteLine(e.StackTrace);
  81. }
  82. }
  83. public static void Check(Document doc)
  84. {
  85. try
  86. {
  87. Console.WriteLine("Start DataCheck");
  88. ServiceDataCheckTest.Check(doc);
  89. Console.WriteLine("End DataCheck");
  90. }
  91. catch (Exception e)
  92. {
  93. Console.WriteLine("导出失败");
  94. Console.WriteLine(e.StackTrace);
  95. }
  96. }
  97. }
  98. }