ParameterIntegrityCheck.cs 4.5 KB

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