XYZOverlapCheck.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* ==============================================================================
  2. * 功能描述:xyz坐标重叠检查
  3. * 创 建 者:Garrett
  4. * 创建日期:2018/10/23 15:08:55
  5. * ==============================================================================*/
  6. using System;
  7. using System.Linq;
  8. using Autodesk.Revit.DB;
  9. using SAGA.RevitUtils;
  10. using SAGA.RevitUtils.Extends;
  11. using ServiceRevitLib.Extend;
  12. using ServiceRevitLib.Mode;
  13. namespace ServiceRevitLib.DataCheck.Mode
  14. {
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. class XYZOverlapCheck : CheckBase
  19. {
  20. public override void Check()
  21. {
  22. try
  23. {
  24. base.Check();
  25. #region
  26. var doc = m_Doc;
  27. var instances = doc.GetFamilyInstances();
  28. var groups = instances.GroupBy(t => t.GetLocationPoint(), new XyzEqualComparer(0.01d));
  29. foreach (var group in groups)
  30. {
  31. var key = group.Key;
  32. if (key == null) continue;
  33. var list = group.ToList();
  34. if (list.Count == 1) continue;
  35. var fi = list.FirstOrDefault();
  36. var result = GetCheckResult(fi);
  37. list.Remove(fi);
  38. if (result == null) continue;
  39. result.ResultMsg = $"与{string.Join(",", list.Select(t => t.Id.ToString()))}的坐标发生重叠,请检查";
  40. Content.Add(result);
  41. }
  42. #endregion
  43. }
  44. catch (Exception e)
  45. {
  46. Result = ResultState.Failure;
  47. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  48. }
  49. }
  50. /// <summary>
  51. /// 获取检测结果
  52. /// </summary>
  53. /// <param name="fi"></param>
  54. /// <returns></returns>
  55. private XYZOverlapCheckResult GetCheckResult(Element fi)
  56. {
  57. var result = new XYZOverlapCheckResult(){ Result = ResultState.Failure};
  58. result.Id = fi.Id.ToString();
  59. result.FamilyName = fi.GetFamilyName();
  60. return result;
  61. }
  62. }
  63. class XYZOverlapCheckResult : ResultBase
  64. {
  65. public string FamilyName { get; set; }
  66. public string Id { get; set; }
  67. }
  68. }