using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Autodesk.Revit.UI; namespace FWindSoft.Revit { /* * 可以使用attribute的形式控制是否自动检索Dockable,并自动注册。读指定的程序集名称 */ public class RevitCustomDockablePanels { #region 静态方法相关 private static List m_DockWindows; static RevitCustomDockablePanels() { m_DockWindows = new List(); DockWindows = new ReadOnlyCollection(m_DockWindows); } public static ReadOnlyCollection DockWindows { get; private set; } /// /// 尝试获取指定Id的Window /// /// /// /// public static bool TryGetCoustomDockWindow(DockablePaneId paneId, out DockableWindow window) { window = DockWindows.FirstOrDefault(c => c.PaneId == paneId); return window != null; } public static DockableWindow AddDockWindow(DockableWindow window) { DockableWindow defaultWin; if (TryGetCoustomDockWindow(window.PaneId, out defaultWin)) { return defaultWin; } else { m_DockWindows.Add(window); } return window; } public static DockablePane GetDockablePane(UIControlledApplication application, DockablePaneId paneId) { return application.GetDockablePane(paneId); } public static DockablePane GetDockablePane(UIApplication application, DockablePaneId paneId) { return application.GetDockablePane(paneId); } public static DockableWindow RegisterDockablePane(UIControlledApplication application, DockablePaneId paneId, string title, DockableWindow provider) { if (DockablePane.PaneExists(paneId)) { throw new Exception("paneId已经注册过"); } application.RegisterDockablePane(paneId, title, provider); return AddDockWindow(provider); } public static DockableWindow RegisterDockablePane(UIApplication application, DockablePaneId paneId, string title, DockableWindow provider) { if (DockablePane.PaneExists(paneId)) { throw new Exception("paneId已经注册过"); } application.RegisterDockablePane(paneId, title, provider); return AddDockWindow(provider); } #endregion public static readonly DockablePaneId Default =new DockablePaneId(new Guid("{3BAFCF52-AC5C-4CF8-B1CB-D0B1D0E90237}")); } }