ParameterIntegrityCheck.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. result.Id = fi.Id.ToString();
  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. rowN.AddCell(++j, result.Id, style);
  108. string rowN4 = result.IsRight ? "通过" : "不通过";
  109. rowN.AddCell(++j, rowN4, style);
  110. rowN.AddCell(++j, result.RMessage, style);
  111. }
  112. #endregion
  113. }
  114. catch (Exception e)
  115. {
  116. MessageShowBase.Show(e);
  117. }
  118. }
  119. }
  120. class ParameterIntegrityCheckResult : ModeCheckResultBase
  121. {
  122. public string FamilyName { get; set; }
  123. public string Id { get; set; }
  124. }
  125. }