ParameterIntegrityCheck.cs 4.5 KB

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