VerticalPipeUtil.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /* ==============================================================================
  2. * 功能描述:VerticalPipeUtil
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/11/5 15:35:20
  5. * ==============================================================================*/
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using Autodesk.Revit.DB;
  12. using FWindSoft.Revit;
  13. using NPOI.SS.UserModel;
  14. using Saga.PlugIn.ModelCheck;
  15. using SAGA.DotNetUtils;
  16. using SAGA.DotNetUtils.Extend;
  17. using SAGA.DotNetUtils.Others;
  18. using SAGA.RevitUtils.MEP;
  19. namespace Saga.PlugIn.VerticalPipeCheck
  20. {
  21. /// <summary>
  22. /// VerticalPipeUtil
  23. /// </summary>
  24. class VerticalPipeUtil
  25. {
  26. public static Tuple<int,int> Execute(string upPath,string downPath,string savePath)
  27. {
  28. try
  29. {
  30. var upPipes = GetVerticalMEPCurves(upPath,true);
  31. var downPipes = GetVerticalMEPCurves(downPath, false);
  32. Action<List<VerticalPipe>, List<VerticalPipe>, string, bool> check = (pipes1, pipes2, path, isup) =>
  33. {
  34. string fileName = path.GetFileName();
  35. foreach (VerticalPipe pipe in pipes1)
  36. {
  37. var pipes = pipes2.Where(t => t.OpenXyz.IsAlmostEqualTo(pipe.OpenXyz));
  38. if (pipes.Any())
  39. {
  40. pipe.TargetFileName = fileName;
  41. pipe.TargetPath = path;
  42. pipe.IsRight = true;
  43. string tip = isup ? "下" : "上";
  44. pipe.RMessage = $"在{tip}层相应位置到了对应的立管。Id:{pipes.FirstOrDefault().MepCurve.Id}";
  45. }
  46. else
  47. {
  48. pipe.TargetFileName = fileName;
  49. pipe.TargetPath = path;
  50. pipe.IsRight = false;
  51. string tip = isup ? "下" : "上";
  52. pipe.RMessage = $"在{tip}层相应位置找不到对应的立管,请检查模型";
  53. }
  54. }
  55. };
  56. check(upPipes, downPipes, downPath, true);
  57. check(downPipes, upPipes, upPath, false);
  58. List<VerticalPipe> results=new List<VerticalPipe>(upPipes);
  59. results.AddRange(downPipes);
  60. results.Sort(new CommonComparer<VerticalPipe>((x, y) => {return x.IsRight.CompareTo(y.IsRight); }));
  61. #region Save
  62. //重置workbook准备保存结果
  63. DCRExport.ClearWorkbook();
  64. //保存
  65. ExportResult(results);
  66. DCRExport.Save(savePath, DCRExport.GetWorkbook());
  67. return new Tuple<int, int>(upPipes.Count,downPipes.Count);
  68. #endregion
  69. }
  70. catch (Exception e)
  71. {
  72. MessageShowBase.Show(e);
  73. }
  74. return null;
  75. }
  76. /// <summary>
  77. /// 获取所有的立管
  78. /// </summary>
  79. /// <param name="path"></param>
  80. /// <param n
  81. /// ame="isup"></param>
  82. /// <returns></returns>
  83. public static List<VerticalPipe> GetVerticalMEPCurves(string path,bool isup)
  84. {
  85. var doc=RevitCore.App.OpenDocumentFile(path);
  86. string fileName = path.GetFileName();
  87. var mepcurves = doc.GetElements<MEPCurve>();
  88. List<VerticalPipe> verticalPipes=new List<VerticalPipe>();
  89. foreach (MEPCurve mepCurve in mepcurves)
  90. {
  91. bool result = false;
  92. var curve = mepCurve.GetLocationCurve();
  93. if (curve is Line line)
  94. {
  95. if (line.Direction.IsParallel(XYZ.BasisZ))
  96. {
  97. var start = line.StartPoint();
  98. var end = line.EndPoint();
  99. XYZ point = null;
  100. if (isup)
  101. {
  102. point = start.Z.IsThan(end.Z) ? start : end;
  103. }
  104. else
  105. {
  106. point = start.Z.IsThan(end.Z) ? end : start;
  107. }
  108. Connector connector = mepCurve.GetNearConnector(point);
  109. if (!connector.IsConnected)
  110. {
  111. VerticalPipe verticalPipe=new VerticalPipe();
  112. verticalPipe.MepCurve = mepCurve;
  113. verticalPipe.OpenXyz = point;
  114. verticalPipe.Path = path;
  115. verticalPipe.FileName = fileName;
  116. verticalPipes.Add(verticalPipe);
  117. }
  118. }
  119. }
  120. }
  121. return verticalPipes;
  122. }
  123. /// <summary>
  124. /// 检查结果汇总
  125. /// </summary>
  126. /// <param name="list"></param>
  127. /// <param name="context"></param>
  128. private static void ExportResult(List<VerticalPipe> list)
  129. {
  130. try
  131. {
  132. IWorkbook book = DCRExport.GetWorkbook();
  133. string sheetName = "立管对齐检查";
  134. ISheet sheet = book.GetSheet(sheetName);
  135. #region 添加数据
  136. int index = 3;
  137. //添加 共检查XXX条数据,未通过检查的如下 提示
  138. IRow rowTip = sheet.CreateRow(index - 1);
  139. //rowTip.AddCell(0, $"总检查{list.Count}条数据,未通过检查的如下", DataCheckNPOIStyle.Title);
  140. foreach (var result in list)
  141. {
  142. if (result.IsRight) continue;
  143. index++;
  144. IRow rowN = sheet.CreateRow(index);
  145. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  146. int j = -1;
  147. rowN.AddCell(++j, result.FileName, style);
  148. rowN.AddCell(++j, result.Path, style);
  149. rowN.AddCell(++j, result.MepCurve.Id.ToString(), style);
  150. rowN.AddCell(++j, result.MepCurve.GetSystemTypeName(), style);
  151. rowN.AddCell(++j, result.TargetFileName, style);
  152. rowN.AddCell(++j, result.TargetPath, style);
  153. string rowN4 = result.IsRight ? "通过" : "不通过";
  154. rowN.AddCell(++j, rowN4, style);
  155. rowN.AddCell(++j, result.RMessage, style);
  156. }
  157. #endregion
  158. }
  159. catch (Exception e)
  160. {
  161. MessageShowBase.Show(e);
  162. }
  163. }
  164. }
  165. class VerticalPipe
  166. {
  167. public MEPCurve MepCurve { get; set; }
  168. public XYZ OpenXyz { get; set; }
  169. public string Path { get; set; }
  170. public string FileName { get; set; }
  171. public string TargetPath { get; set; }
  172. public string TargetFileName { get; set; }
  173. /// <summary>
  174. /// 是否通过较验
  175. /// </summary>
  176. public bool IsRight { get; set; }
  177. /// <summary>
  178. /// 提示信息
  179. /// </summary>
  180. public string RMessage { get; set; }
  181. }
  182. }