void OnIdle(object sender, EventArgs e) { //Make sure ribbon manager is available if (Autodesk.Windows.ComponentManager.Ribbon != null) { //Create tab if it doesn't exist if (_ctxTab == null) { CreateCtxTab(); } //Otherwise make it visible if (!_ctxTab.IsVisible) { Autodesk.Windows.RibbonControl ribbonCtrl = Autodesk.Windows.ComponentManager.Ribbon; ribbonCtrl.ShowContextualTab(_ctxTab, false, true); _ctxTab.IsActive = true; } if (!_ctxTab.IsActive) { _ctxTab.IsActive = true; } } }
void HideTab() { Autodesk.AutoCAD.ApplicationServices.Application.Idle -= new EventHandler(OnIdle); if (_ctxTab != null) { Autodesk.Windows.RibbonControl ribbonCtrl = Autodesk.Windows.ComponentManager.Ribbon; ribbonCtrl.HideContextualTab(_ctxTab); _ctxTab.IsVisible = false; _ctxTab = null; } }
//Tab creation method void CreateCtxTab() { Autodesk.Windows.RibbonControl ribbonCtrl = Autodesk.Windows.ComponentManager.Ribbon; _ctxTab = new Autodesk.Windows.RibbonTab(); _ctxTab.Name = "MyTab"; _ctxTab.Id = "MY_CTX_TAB_ID"; _ctxTab.IsVisible = true; _ctxTab.Title = _ctxTab.Name; _ctxTab.IsContextualTab = true; ribbonCtrl.Tabs.Add(_ctxTab); }
public Result OnStartup( UIControlledApplication a) { _controlledApp = a; // Locate and load button images. //string AddInPath = typeof( App ).Assembly.Location; //string iconPath = Path.GetDirectoryName( AddInPath ).ToLower(); //string lastDir = new DirectoryInfo( iconPath ).Name; //iconPath = iconPath.Replace( "\\" + lastDir, "\\icons\\" ); //Uri uriImage = new Uri( iconPath + "image.ico" ); //BitmapImage image = new BitmapImage( uriImage ); // PresentationCore BitmapSource image = GetEmbeddedImage( "ModifyTabButton.icon.cartoon_house_16.ico"); // Add modify panel Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon; foreach (Autodesk.Windows.RibbonTab tab in ribbon.Tabs) { if (tab.Id == "Modify") { _modifyPanel = new Autodesk.Windows.RibbonPanel(); _modifyPanel.IsVisible = false; Autodesk.Windows.RibbonPanelSource source = new Autodesk.Windows.RibbonPanelSource(); source.Name = "mymod"; source.Id = "mymod"; source.Title = "My Modify"; _modifyPanel.Source = source; _modifyPanel.FloatingOrientation = System.Windows.Controls.Orientation.Vertical; _button1 = CreateButton(1, image); _button2 = CreateButton(2, image); _button3 = CreateButton(3, image); Autodesk.Windows.ComponentManager.UIElementActivated += new EventHandler < Autodesk.Windows.UIElementActivatedEventArgs>( OnUiElementActivated); Autodesk.Windows.RibbonRowPanel rowPanel = new Autodesk.Windows.RibbonRowPanel(); rowPanel.Items.Add(_button1); rowPanel.Items.Add(new Autodesk.Windows.RibbonRowBreak()); rowPanel.Items.Add(_button2); rowPanel.Items.Add(new Autodesk.Windows.RibbonRowBreak()); rowPanel.Items.Add(_button3); _modifyPanel.Source.Items.Add(rowPanel); tab.Panels.Add(_modifyPanel); tab.Panels.CollectionChanged += new System.Collections.Specialized .NotifyCollectionChangedEventHandler( OnCollectionChanged); a.ViewActivated += new EventHandler <ViewActivatedEventArgs>( OnViewActivated); break; } } return(Result.Succeeded); }
public Result OnStartup(UIControlledApplication application) { address = new Uri(addr + application.ControlledApplication.VersionNumber); uicApp = application; _app = this; serverActive = Properties.Settings.Default.defaultServerOn; // Create the button try { BitmapSource bms; PushButtonData lyrebirdButton; //StartServer(); if (disableButton) { bms = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.Lyrebird_On.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); lyrebirdButton = new PushButtonData("Lyrebird Server", "Lyrebird Server\nDisabled", typeof(RevitServerApp).Assembly.Location, "LMNA.Lyrebird.ServerToggle") { LargeImage = bms, ToolTip = "The Lyrebird Server is currently disabled in this session of Revit. This is most likely because you have more than one session of Revit and the server can only run in one.", }; Properties.Settings.Default.enableServer = false; Properties.Settings.Default.Save(); } else { if (serverActive) { bms = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.Lyrebird_On.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); lyrebirdButton = new PushButtonData("Lyrebird Server", "Lyrebird\nServer On", typeof(RevitServerApp).Assembly.Location, "LMNA.Lyrebird.ServerToggle") { LargeImage = bms, ToolTip = "The Lyrebird Server currently on and will accept requests for data and can create objects. Push button to toggle the server off.", }; StartServer(); //ServiceOn(); } else { bms = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.Lyrebird_Off.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); lyrebirdButton = new PushButtonData("Lyrebird Server", "Lyrebird\nServer Off", typeof(RevitServerApp).Assembly.Location, "LMNA.Lyrebird.ServerToggle") { LargeImage = bms, ToolTip = "The Lyrebird Server is currently off and will not accept requests for data or create objects. Push button to toggle the server on.", }; } Properties.Settings.Default.enableServer = true; Properties.Settings.Default.Save(); } // Settings button BitmapSource setBMS = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.Lyrebird_Settings.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); PushButtonData settingsButtonData = new PushButtonData("Lyrebird Settings", "Lyrebird Settings", typeof(RevitServerApp).Assembly.Location, "LMNA.Lyrebird.SettingsCmd") { LargeImage = setBMS, ToolTip = "Lyrebird Server settings.", }; // Selection button BitmapSource selBMS = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.Lyrebird_Select.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); PushButtonData selectionButtonData = new PushButtonData("Select Run", "Select Run", typeof(RevitServerApp).Assembly.Location, "LMNA.Lyrebird.SelectRunElementsCmd") { LargeImage = selBMS, ToolTip = "Select elements created from Lyrebird", }; // Selection button BitmapSource delBMS = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(Properties.Resources.Lyrebird_RemoveData.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); PushButtonData removeButtonData = new PushButtonData("Remove Data", "Remove Data", typeof(RevitServerApp).Assembly.Location, "LMNA.Lyrebird.RemoveDataCmd") { LargeImage = delBMS, ToolTip = "Remove Lyrebird data from selected elements", }; // Create the tab if necessary const string tabName = "LMN"; Autodesk.Windows.RibbonControl ribbon = Autodesk.Windows.ComponentManager.Ribbon; Autodesk.Windows.RibbonTab tab = null; foreach (Autodesk.Windows.RibbonTab t in ribbon.Tabs) { if (t.Id == tabName) { tab = t; } } if (tab == null) { application.CreateRibbonTab(tabName); } bool found = false; List <RibbonPanel> panels = application.GetRibbonPanels(tabName); RibbonPanel panel = null; foreach (RibbonPanel rp in panels) { if (rp.Name == "Utilities") { panel = rp; found = true; } } SplitButtonData sbd = new SplitButtonData("Lyrebird", "Lyrebird"); if (!found) { // Create the panel RibbonPanel utilitiesPanel = application.CreateRibbonPanel(tabName, "Utilities"); // Split button SplitButton sb = utilitiesPanel.AddItem(sbd) as SplitButton; serverButton = sb.AddPushButton(lyrebirdButton) as PushButton; PushButton settingsButton = sb.AddPushButton(settingsButtonData) as PushButton; PushButton selButton = sb.AddPushButton(selectionButtonData) as PushButton; PushButton removeButton = sb.AddPushButton(removeButtonData) as PushButton; sb.IsSynchronizedWithCurrentItem = false; } else { SplitButton sb = panel.AddItem(sbd) as SplitButton; serverButton = sb.AddPushButton(lyrebirdButton) as PushButton; PushButton settingsButton = sb.AddPushButton(settingsButtonData) as PushButton; PushButton selButton = sb.AddPushButton(selectionButtonData) as PushButton; PushButton removeButton = sb.AddPushButton(removeButtonData) as PushButton; sb.IsSynchronizedWithCurrentItem = false; } if (disableButton) { serverButton.Enabled = false; } } catch (Exception ex) { TaskDialog.Show("Error", ex.ToString()); } return(Result.Succeeded); }