Program.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. command = "DataExport";
  36. path = @"E:\导出测试\test.rvt";
  37. #endif
  38. if (string.IsNullOrEmpty(command))
  39. {
  40. Console.WriteLine("命令参数错误");
  41. }
  42. if (File.Exists(path)&&Enum.TryParse(command, out CommandType commandType))
  43. {
  44. var app = RevitCoreContext.Instance.Application;
  45. var doc = app.OpenDocumentFile(path);
  46. switch (commandType)
  47. {
  48. case CommandType.DataCheck:
  49. Check(doc);
  50. break;
  51. case CommandType.DataExport:
  52. Export(doc);
  53. break;
  54. }
  55. RevitCoreContext.Instance.Stop();
  56. }
  57. }
  58. enum CommandType
  59. {
  60. None = 0,
  61. DataCheck,
  62. DataExport
  63. }
  64. public static void Export(Document doc)
  65. {
  66. try
  67. {
  68. Console.WriteLine("Start Export");
  69. RevitToJBim.MbiExport.Export(doc);
  70. Console.WriteLine("End Export");
  71. }
  72. catch (Exception e)
  73. {
  74. Console.WriteLine("导出失败");
  75. Console.WriteLine(e.StackTrace);
  76. }
  77. }
  78. public static void Check(Document doc)
  79. {
  80. try
  81. {
  82. Console.WriteLine("Start DataCheck");
  83. ServiceDataCheckTest.Check(doc);
  84. Console.WriteLine("End DataCheck");
  85. }
  86. catch (Exception e)
  87. {
  88. Console.WriteLine("导出失败");
  89. Console.WriteLine(e.StackTrace);
  90. }
  91. }
  92. }
  93. }