UnitCheck.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* ==============================================================================
  2. * 功能描述:SagaCheck
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:09:09
  5. * ==============================================================================*/
  6. using System;
  7. using Autodesk.Revit.DB;
  8. namespace ServiceRevitLib.Mode
  9. {
  10. /// <summary>
  11. /// SagaCheck
  12. /// </summary>
  13. class UnitCheck : CheckBase
  14. {
  15. public override void Check()
  16. {
  17. try
  18. {
  19. base.Check();
  20. #region
  21. string resultMsg = null;
  22. ResultState resultState = ResultState.Failure;
  23. string unit = "";
  24. var formatOptions = m_Doc.GetUnits().GetFormatOptions(UnitType.UT_Length);
  25. var ismmUnit = formatOptions.DisplayUnits == DisplayUnitType.DUT_MILLIMETERS;
  26. unit = formatOptions.DisplayUnits.ToString();
  27. if (!ismmUnit)
  28. {
  29. resultMsg = "单位异常,请修改长度单位为毫米(mm)";
  30. resultState = ResultState.Failure;
  31. }
  32. else
  33. {
  34. resultState = ResultState.Success;
  35. }
  36. Content.Add(new UnitCheckResult() { Unit = unit, Result = resultState, ResultMsg = resultMsg });
  37. #endregion
  38. }
  39. catch (Exception e)
  40. {
  41. Result = ResultState.Failure;
  42. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  43. }
  44. }
  45. }
  46. }