123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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<DockableWindow> m_DockWindows;
- static RevitCustomDockablePanels()
- {
- m_DockWindows = new List<DockableWindow>();
- DockWindows = new ReadOnlyCollection<DockableWindow>(m_DockWindows);
- }
- public static ReadOnlyCollection<DockableWindow> DockWindows { get; private set; }
- /// <summary>
- /// 尝试获取指定Id的Window
- /// </summary>
- /// <param name="paneId"></param>
- /// <param name="window"></param>
- /// <returns></returns>
- 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}"));
- }
- }
|