RevitCustomDockablePanels.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using Autodesk.Revit.UI;
  6. namespace FWindSoft.Revit
  7. {
  8. /*
  9. * 可以使用attribute的形式控制是否自动检索Dockable,并自动注册。读指定的程序集名称
  10. */
  11. public class RevitCustomDockablePanels
  12. {
  13. #region 静态方法相关
  14. private static List<DockableWindow> m_DockWindows;
  15. static RevitCustomDockablePanels()
  16. {
  17. m_DockWindows = new List<DockableWindow>();
  18. DockWindows = new ReadOnlyCollection<DockableWindow>(m_DockWindows);
  19. }
  20. public static ReadOnlyCollection<DockableWindow> DockWindows { get; private set; }
  21. /// <summary>
  22. /// 尝试获取指定Id的Window
  23. /// </summary>
  24. /// <param name="paneId"></param>
  25. /// <param name="window"></param>
  26. /// <returns></returns>
  27. public static bool TryGetCoustomDockWindow(DockablePaneId paneId, out DockableWindow window)
  28. {
  29. window = DockWindows.FirstOrDefault(c => c.PaneId == paneId);
  30. return window != null;
  31. }
  32. public static DockableWindow AddDockWindow(DockableWindow window)
  33. {
  34. DockableWindow defaultWin;
  35. if (TryGetCoustomDockWindow(window.PaneId, out defaultWin))
  36. {
  37. return defaultWin;
  38. }
  39. else
  40. {
  41. m_DockWindows.Add(window);
  42. }
  43. return window;
  44. }
  45. public static DockablePane GetDockablePane(UIControlledApplication application, DockablePaneId paneId)
  46. {
  47. return application.GetDockablePane(paneId);
  48. }
  49. public static DockablePane GetDockablePane(UIApplication application, DockablePaneId paneId)
  50. {
  51. return application.GetDockablePane(paneId);
  52. }
  53. public static DockableWindow RegisterDockablePane(UIControlledApplication application, DockablePaneId paneId, string title, DockableWindow provider)
  54. {
  55. if (DockablePane.PaneExists(paneId))
  56. {
  57. throw new Exception("paneId已经注册过");
  58. }
  59. application.RegisterDockablePane(paneId, title, provider);
  60. return AddDockWindow(provider);
  61. }
  62. public static DockableWindow RegisterDockablePane(UIApplication application, DockablePaneId paneId, string title, DockableWindow provider)
  63. {
  64. if (DockablePane.PaneExists(paneId))
  65. {
  66. throw new Exception("paneId已经注册过");
  67. }
  68. application.RegisterDockablePane(paneId, title, provider);
  69. return AddDockWindow(provider);
  70. }
  71. #endregion
  72. public static readonly DockablePaneId Default =new DockablePaneId(new Guid("{3BAFCF52-AC5C-4CF8-B1CB-D0B1D0E90237}"));
  73. }
  74. }