SagaCheck.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* ==============================================================================
  2. * 功能描述:SagaCheck
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:09:09
  5. * ==============================================================================*/
  6. using System;
  7. using System.Linq;
  8. using System.Text.RegularExpressions;
  9. using Autodesk.Revit.DB;
  10. using SAGA.DotNetUtils.Extend;
  11. using SAGA.RevitUtils.Extends;
  12. using ServiceRevitLib.Common;
  13. using ServiceRevitLib.Mode;
  14. namespace ServiceRevitLib.DataCheck.Mode
  15. {
  16. /// <summary>
  17. /// SagaCheck
  18. /// </summary>
  19. class SagaCheck : CheckBase
  20. {
  21. public override void Check()
  22. {
  23. try
  24. {
  25. base.Check();
  26. #region
  27. string resultMsg = null;
  28. ResultState resultState = 0;
  29. string planName = "";
  30. //判断是否存在Saga标记
  31. var document = m_Doc;
  32. var sagaPlans = document.GetElements<ViewPlan>()
  33. .Where(t => t.ViewType == ViewType.FloorPlan && t.Name.Contains("-saga")).ToList();
  34. if (sagaPlans.Count == 0)
  35. {
  36. resultState = ResultState.Failure;
  37. resultMsg = "缺少saga标记";
  38. }
  39. else if (sagaPlans.Count() >= 2)
  40. {
  41. resultState = ResultState.Failure;
  42. resultMsg = "有多个saga标记";
  43. }
  44. else
  45. {
  46. //只有一个saga标记
  47. var sagaPlan = sagaPlans.FirstOrDefault();
  48. if (sagaPlan != null)
  49. {
  50. planName = sagaPlan.Name;
  51. //打标记的楼层名称必需为指定格式;B1,B1M,F1,F1M,RFM,RF
  52. if (Regex.IsMatch(planName, $"{RegexConstPattern.IsMBIView}"))
  53. {
  54. var rfLevel = document.GetLevels().FirstOrDefault(t =>
  55. System.Text.RegularExpressions.Regex.IsMatch(t.Name, $"{RegexConstPattern.IsRF}"));
  56. if (rfLevel == null)
  57. {
  58. resultState = ResultState.Failure;
  59. resultMsg = $"缺少RF标高";
  60. }
  61. else
  62. {
  63. if (rfLevel.Elevation.IsThanEq(sagaPlan.GenLevel.Elevation))
  64. {
  65. resultState = ResultState.Success;
  66. }
  67. else
  68. {
  69. resultState = ResultState.Failure;
  70. resultMsg = $"RF标高的位置不正确,请检查";
  71. }
  72. }
  73. }
  74. else
  75. {
  76. resultState = ResultState.Failure;
  77. resultMsg = $"楼层 {planName} 不符合楼层命名规范";
  78. }
  79. }
  80. }
  81. Content.Add(new SagaCheckResult() { PlanName = planName, Result = resultState, ResultMsg = resultMsg });
  82. #endregion
  83. }
  84. catch (Exception e)
  85. {
  86. Result = ResultState.Failure;
  87. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  88. }
  89. }
  90. }
  91. }