SagaCheck.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 ServiceRevitLib.Common;
  12. using SAGA.RevitUtils.Extends;
  13. namespace ServiceRevitLib.Mode
  14. {
  15. /// <summary>
  16. /// SagaCheck
  17. /// </summary>
  18. class SagaCheck : CheckBase
  19. {
  20. public override void Check()
  21. {
  22. base.Check();
  23. #region
  24. string resultMsg = null;
  25. ResultState resultState = 0;
  26. string planName = "";
  27. //判断是否存在Saga标记
  28. var document = m_Doc;
  29. var sagaPlans = document.GetElements<ViewPlan>()
  30. .Where(t => t.ViewType == ViewType.FloorPlan && t.Name.Contains("-saga")).ToList();
  31. if (sagaPlans.Count == 0)
  32. {
  33. resultState = ResultState.Failure;
  34. resultMsg = "缺少saga标记";
  35. }
  36. else if (sagaPlans.Count() >= 2)
  37. {
  38. resultState = ResultState.Failure;
  39. resultMsg = "有多个saga标记";
  40. }
  41. else
  42. {
  43. //只有一个saga标记
  44. var sagaPlan = sagaPlans.FirstOrDefault();
  45. if (sagaPlan != null)
  46. {
  47. planName = sagaPlan.Name;
  48. //打标记的楼层名称必需为指定格式;B1,B1M,F1,F1M,RFM,RF
  49. if (Regex.IsMatch(planName, $"{RegexConstPattern.IsMBIView}"))
  50. {
  51. var rfLevel = document.GetLevels().FirstOrDefault(t =>
  52. System.Text.RegularExpressions.Regex.IsMatch(t.Name, $"{RegexConstPattern.IsRF}"));
  53. if (rfLevel == null)
  54. {
  55. resultState = ResultState.Failure;
  56. resultMsg = $"缺少RF标高";
  57. }
  58. else
  59. {
  60. if (rfLevel.Elevation.IsThanEq(sagaPlan.GenLevel.Elevation))
  61. {
  62. resultState = ResultState.Success;
  63. }
  64. else
  65. {
  66. resultState = ResultState.Failure;
  67. resultMsg = $"RF标高的位置不正确,请检查";
  68. }
  69. }
  70. }
  71. else
  72. {
  73. resultState = ResultState.Failure;
  74. resultMsg = $"楼层 {planName} 不符合楼层命名规范";
  75. }
  76. }
  77. }
  78. Content.Add(new SagaCheckResult() {PlanName = planName, Result = resultState, ResultMsg = resultMsg});
  79. #endregion
  80. }
  81. }
  82. }