ParameterIntegrityCheck.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* ==============================================================================
  2. * 功能描述:Revit族参数完整性检查
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/10/23 15:08:55
  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 NPOI.SS.UserModel;
  13. using SAGA.DotNetUtils;
  14. using SAGA.DotNetUtils.Extend;
  15. using SAGA.DotNetUtils.Others;
  16. using SAGA.MBI.Common;
  17. using SAGA.MBI.Tools;
  18. using SAGA.MBI.ToolsData.CheckBase;
  19. using SAGA.RevitUtils.Extends;
  20. using SAGA.RevitUtils.MEP;
  21. namespace SAGA.MBI.ToolsData.ModeCheck
  22. {
  23. /// <summary>
  24. /// UnitCheck
  25. /// </summary>
  26. class ParameterIntegrityCheck : ModeCheckBase
  27. {
  28. public ParameterIntegrityCheck()
  29. {
  30. Name = "Revit族参数完整性检查";
  31. }
  32. [DataCheckProcessAspect]
  33. public override bool Check()
  34. {
  35. if (!RBase.IsRight)
  36. {
  37. IsRight = RBase.IsRight;
  38. return IsRight;
  39. }
  40. IsRight = FamilyNameCodeCheck();
  41. return IsRight;
  42. }
  43. public override void Correct()
  44. {
  45. throw new NotImplementedException();
  46. }
  47. /// <summary>
  48. /// 族名称编码规范检查
  49. /// </summary>
  50. /// <returns></returns>
  51. private bool FamilyNameCodeCheck()
  52. {
  53. bool unitResult = true;
  54. foreach (SagaSignCheckResult signResult in RBase.Results)
  55. {
  56. var doc = signResult.RDocument;
  57. var instances = doc.GetMbiElements();
  58. var mbiItems = instances.Where(t => t.IsEquipment() || t.IsEquipmentPart()).ToList();
  59. var familyGroups = mbiItems.GroupBy(t => t.GetFamilyName());
  60. foreach (IGrouping<string, Element> familyGroup in familyGroups)
  61. {
  62. string familyName = familyGroup.Key;
  63. Element fi = familyGroup.FirstOrDefault();
  64. var result = GetCheckResult(fi);
  65. if (result == null) continue;
  66. result.FamilyName = familyName;
  67. result.RBase = signResult;
  68. Results.Add(result);
  69. }
  70. }
  71. return Results.All(t => t.IsRight);
  72. }
  73. /// <summary>
  74. /// 获取检测结果
  75. /// </summary>
  76. /// <param name="fi"></param>
  77. /// <returns></returns>
  78. private ParameterIntegrityCheckResult GetCheckResult(Element fi)
  79. {
  80. var result = new ParameterIntegrityCheckResult(){IsRight = true};
  81. var localNameParameter = fi.GetParameter(RevitBuiltInParameter.EquipLocalName);
  82. var localIdParameter = fi.GetParameter(RevitBuiltInParameter.EquipLocalID);
  83. result.Id = fi.Id.ToString();
  84. List<string> list=new List<string>();
  85. if(localIdParameter==null)
  86. list.Add(RevitBuiltInParameter.EquipLocalID);
  87. if(localNameParameter==null)
  88. list.Add(RevitBuiltInParameter.EquipLocalName);
  89. if (list.Count > 0)
  90. {
  91. result.IsRight = false;
  92. result.RMessage = $"缺失的参数为:{string.Join("、", list)}";
  93. }
  94. return result;
  95. }
  96. //[DataCheckProcessAspect]
  97. public override void Export()
  98. {
  99. // Check();
  100. try
  101. {
  102. IWorkbook book = DCRExport.GetWorkbook();
  103. ISheet sheet = book.GetSheet(Name);
  104. #region 添加数据
  105. int index = 3;
  106. foreach (ParameterIntegrityCheckResult result in Results)
  107. {
  108. SagaSignCheckResult rbase = result.RBase as SagaSignCheckResult;
  109. if (rbase == null)
  110. continue;
  111. //数量多过,只显示有问题的
  112. if (result.IsRight) continue;
  113. index++;
  114. IRow rowN = sheet.CreateRow(index);
  115. DataCheckNPOIStyle style = result.IsRight ? DataCheckNPOIStyle.Content : DataCheckNPOIStyle.Error;
  116. int c = 0;
  117. rowN.AddCell(c++, rbase.RFloorName, style);
  118. rowN.AddCell(c++, rbase.RFileName, style);
  119. rowN.AddCell(c++, rbase.RPath, style);
  120. rowN.AddCell(c++, result.FamilyName, style);
  121. rowN.AddCell(c++, result.Id, style);
  122. string rowN4 = result.IsRight ? "通过" : "不通过";
  123. rowN.AddCell(c++, rowN4, style);
  124. rowN.AddCell(c++, result.RMessage, style);
  125. }
  126. #endregion
  127. }
  128. catch (Exception e)
  129. {
  130. MessageShowBase.Show(e);
  131. }
  132. }
  133. }
  134. }