XYZOverlapCheck.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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().Where(t=>t.GetLocationPoint()!=null);
  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. Result = ResultState.Success;
  49. ResultMsg = $"";
  50. }
  51. }
  52. /// <summary>
  53. /// 获取检测结果
  54. /// </summary>
  55. /// <param name="fi"></param>
  56. /// <returns></returns>
  57. private XYZOverlapCheckResult GetCheckResult(Element fi)
  58. {
  59. var result = new XYZOverlapCheckResult(){ Result = ResultState.Failure};
  60. result.Id = fi.Id.ToString();
  61. result.FamilyName = fi.GetFamilyName();
  62. return result;
  63. }
  64. }
  65. class XYZOverlapCheckResult : ResultBase
  66. {
  67. public string FamilyName { get; set; }
  68. public string Id { get; set; }
  69. }
  70. }