ExportCombineWall.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* ==============================================================================
  2. * 功能描述:ExportCombineWall
  3. * 创 建 者:Garrett
  4. * 创建日期:2017/11/21 16:21:22
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Threading;
  14. using System.Threading.Tasks;
  15. using Autodesk.Revit.DB;
  16. using Autodesk.Revit.DB.Mechanical;
  17. using Autodesk.Revit.UI;
  18. using NPOI.OpenXmlFormats;
  19. using NPOI.SS.Formula.Functions;
  20. using SAGA.DotNetUtils;
  21. using SAGA.DotNetUtils.Extend;
  22. using SAGA.RevitUtils;
  23. using SAGA.RevitUtils.Extends;
  24. using SAGA.RevitUtils.Windows;
  25. using SpacePlugin.CobineWall;
  26. using Point = System.Windows.Point;
  27. namespace SpacePlugin
  28. {
  29. /// <summary>
  30. /// ExportCombineWall
  31. /// </summary>
  32. public class ExportCombineWall
  33. {
  34. public static void ExportWall()
  35. {
  36. var path = Path.Combine(AppBaseInfo.AppRunPath, @"MBIResource\北京市海淀区0021号项目");
  37. DirectoryInfo folder = new DirectoryInfo(path);
  38. foreach (var dicInfo in folder.GetDirectories())
  39. {
  40. FileInfo[] fileInfos = dicInfo.GetFiles("*.rvt").Where(t => !t.Name.Is000File()).ToArray();
  41. foreach (FileInfo file in fileInfos)
  42. {
  43. string filePath = file.FullName;
  44. ExportWall(filePath);
  45. }
  46. }
  47. }
  48. public static void ExportWall(string filePath)
  49. {
  50. ExportParallelWall(filePath);
  51. ExportVirtualizeWallResult(filePath);
  52. CreateSegmSpace(filePath);
  53. }
  54. /// <summary>
  55. /// 导出给定路径Revit文件下面的Wall
  56. /// </summary>
  57. /// <param name="path"></param>
  58. public static void ExportParallelWall(string path)
  59. {
  60. var uiApp = ExternalDataWrapper.Current.UiApp;
  61. var linkDoc = uiApp.Application.OpenDocumentFile(path);
  62. List<Element> linkElements = linkDoc.GetAllElements(false);
  63. var walls = linkElements.Where(t => t is Wall).ToList<Wall>();
  64. if (!walls.Any()) return;
  65. try
  66. {
  67. var xyzs = WallOperationFactory.GroupWallByParallel(walls).ToList();
  68. var fullName = path.GetAppointSuffixPath(".xlsx");
  69. NpoiHelper.ExportToExcel(xyzs, fullName, 0);
  70. }
  71. catch (Exception e)
  72. {
  73. MessageShow.Show(e);
  74. }
  75. }
  76. /// <summary>
  77. /// 导出虚拟墙结果
  78. /// </summary>
  79. public static void ExportVirtualizeWallResult(string path)
  80. {
  81. try
  82. {
  83. var wallPath = path.GetAppointSuffixPath(".xlsx");
  84. if (wallPath == null) return;
  85. var strAsmblPath = Path.Combine(AppBaseInfo.AppRunPath, @"MBIResource\VirtualizeWallCalc\GraphTest.exe"); ;
  86. // ExportCombineWall.ExportWall();
  87. var asmbl = Assembly.LoadFrom(strAsmblPath);
  88. var frmController = asmbl.CreateInstance("GraphTest.ExportVWCurves");
  89. if (frmController != null)
  90. {
  91. var calcMethod = frmController.GetType().GetMethod("Calc");
  92. calcMethod?.Invoke(frmController, new object[] { wallPath });
  93. }
  94. }
  95. catch (Exception e)
  96. {
  97. Console.WriteLine(e);
  98. throw;
  99. }
  100. }
  101. /// <summary>
  102. /// 创建虚拟墙
  103. /// </summary>
  104. /// <param name="path"></param>
  105. public static void CreateVirtualizeWall(string path)
  106. {
  107. try
  108. {
  109. AutoCreateSpace.CreateSpace(path);
  110. }
  111. catch (Exception e)
  112. {
  113. MessageShow.Show(e);
  114. }
  115. }
  116. /// <summary>
  117. /// 创建虚拟墙并自动放置空间
  118. /// </summary>
  119. /// <param name="path"></param>
  120. public static void CreateSegmSpace(string path)
  121. {
  122. try
  123. {
  124. AutoCreateSpace.CreateSpace(path);
  125. }
  126. catch (Exception e)
  127. {
  128. MessageShow.Show(e);
  129. }
  130. }
  131. }
  132. }