FamilyNameCheck.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* ==============================================================================
  2. * 功能描述:SagaCheck
  3. * 创 建 者:Garrett
  4. * 创建日期:2019/6/11 16:09:09
  5. * ==============================================================================*/
  6. using System;
  7. using System.Linq;
  8. using Autodesk.Revit.DB;
  9. using SAGA.RevitUtils.Extends;
  10. using ServiceRevitLib.Extend;
  11. using ServiceRevitLib.Mode;
  12. using ServiceRevitLib.Utils;
  13. namespace ServiceRevitLib.DataCheck.Mode
  14. {
  15. /// <summary>
  16. /// SagaCheck
  17. /// </summary>
  18. class FamilyNameCheck : CheckBase
  19. {
  20. public FamilyNameCheck()
  21. {
  22. ReferenceSheet = "参考-revit分类";
  23. }
  24. public override void Check()
  25. {
  26. try
  27. {
  28. base.Check();
  29. #region
  30. var ccategories = DataCheckRule.GetCodeCheckCategories();
  31. var categories = m_Doc.Settings.Categories;
  32. foreach (DCR_CodeCheckCategory ccategory in ccategories)
  33. {
  34. try
  35. {
  36. var category = categories.get_Item(ccategory.Name);
  37. if (category == null) continue;
  38. BuiltInCategory builtInCategory = (BuiltInCategory)category.Id.IntegerValue;
  39. var elements = m_Doc.GetElements<FamilyInstance>(builtInCategory);
  40. var groupByFamily = elements.GroupBy(t => t.GetFamilyName());
  41. foreach (IGrouping<string, FamilyInstance> grouping in groupByFamily)
  42. {
  43. var subElements = grouping.ToList();
  44. var subElement = subElements.FirstOrDefault();
  45. if (subElement is FamilyInstance fi)
  46. {
  47. var result = new FamilyNameCheckResult();
  48. result.FamilyName = grouping.Key;
  49. if (fi.IsEquipment() || fi.IsEquipmentPart() || fi.IsBeacon())
  50. {
  51. result.Result = ResultState.Success;
  52. }
  53. else
  54. {
  55. result.Result = ResultState.Failure;
  56. result.ResultMsg = "请检查族名称编码是否符合要求";
  57. }
  58. Content.Add(result);
  59. }
  60. }
  61. }
  62. catch (Exception e)
  63. {
  64. Console.WriteLine(e);
  65. }
  66. }
  67. #endregion
  68. }
  69. catch (Exception e)
  70. {
  71. Result = ResultState.Failure;
  72. ResultMsg = $"{e.Message}\r\n{e.StackTrace}";
  73. }
  74. }
  75. }
  76. }