ElementPath.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Autodesk.Revit.DB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace FWindSoft.Revit
  8. {
  9. /// <summary>
  10. /// 元素集合相关
  11. /// </summary>
  12. public class ElementPath:List<Element>
  13. {
  14. public bool FirstIsType<T>()
  15. {
  16. return FirstIsMath(e => e is T);
  17. }
  18. public bool FirstIsMath(Predicate<Element> predicate)
  19. {
  20. var useElement = this.FirstOrDefault();
  21. if (useElement == null)
  22. return false;
  23. return predicate(useElement);
  24. }
  25. public bool LastIsType<T>()
  26. {
  27. return LastIsMatch(e => e is T);
  28. }
  29. public bool LastIsMatch(Predicate<Element> predicate)
  30. {
  31. var useElement = this.LastOrDefault();
  32. if (useElement == null)
  33. return false;
  34. return predicate(useElement);
  35. }
  36. public bool IsMatch(ElementPath path)
  37. {
  38. return this.Select(e => e.Id.IntegerValue)
  39. .Intersect(path.Select(e => e.Id.IntegerValue))
  40. .Count() == path.Count();
  41. }
  42. #region 重写方法
  43. public override string ToString()
  44. {
  45. return string.Join(",", this.Select(e => e.Id.ToString()));
  46. }
  47. #endregion
  48. }
  49. }