UnitCheck.cs 1.6 KB

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