FamilyNameCheck.cs 2.7 KB

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