private void listing3_SelectedIndexChanged(object sender, EventArgs e) { if (listing3.SelectedItems.Count == 1) { adWin.RibbonItem item = (adWin.RibbonItem)listing3.SelectedItems[0].Tag; if (item.Id == "ID_IFC_LINK") { ((adWin.RibbonButton)item).CommandHandler.Execute(null); } } }
protected override bool CanExecute(Autodesk.Windows.RibbonItem parameter) { if (parameter == null) { return(true); } if (parameter.Tag is UIApplication uiApp) { return(uiApp.ActiveUIDocument != null); } return(true); }
static void OnItemExecuted( object sender, Autodesk.Internal.Windows .RibbonItemExecutedEventArgs e) { string s = (null == sender) ? "<nul>" : sender.ToString(); Autodesk.Windows.RibbonItem parent = e.Parent; Debug.Print( "OnItemExecuted: {0} '{1}' in '{2}' cookie {3}", s, parent.AutomationName, e.Item.AutomationName, e.Item.Cookie); }
/// <summary> /// Create a stack of 3 buttons in the Revit UI. /// </summary> /// <param name="revApp">Revit's UIControlledApplication for adding the button</param> /// <param name="tabName">Name of the tab you want to add the button to.</param> /// <param name="panelName">Name of the panel on the tab you want to add the button</param> /// <param name="button0">Top button in the stack</param> /// <param name="button1">Middle button in the stack</param> /// <param name="button2">Bottom button in the stack</param> /// <param name="stackName">Name of the stacked panel that these buttons belong to.</param> public static bool AddToRibbon(UIControlledApplication revApp, string tabName, string panelName, PushButtonData button0, PushButtonData button1, PushButtonData button2, string stackName) { RibbonPanel panel = GetRibbonPanel(revApp, tabName, panelName); // Add the button to the panel if (panel != null) { panel.AddStackedItems(button0, button1, button2); } else { TaskDialog.Show("Error", "Could not create stacked buttons for:\n" + button0.Text + "\n" + button1.Text + "\n" + button2.Text); } adWin.RibbonItem i = null; foreach (adWin.RibbonTab t in adWin.ComponentManager.Ribbon.Tabs) { foreach (adWin.RibbonPanel p in t.Panels) { if (p.Source.Name == panelName) { foreach (adWin.RibbonItem item in p.Source.Items) { i = item; } } } } // Try to set the name. if (i is adWin.RibbonRowPanel) // Stacked buttons { i.Text = stackName; } return(true); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { if (_subscribed) { Autodesk.Windows.ComponentManager.ItemExecuted -= OnItemExecuted; _subscribed = false; } else { RibbonTabCollection tabs = ComponentManager.Ribbon.Tabs; foreach (RibbonTab tab in tabs) { Debug.Print(" {0} {1} '{2}'", tab, tab.GetType().Name, tab.AutomationName); if (tab.KeyTip == null) { // This tab is user defined. foreach (var panel in tab.Panels) { // Cannot convert type 'Autodesk.Windows.RibbonPanel' // to 'Autodesk.Revit.UI.RibbonPanel' via a reference // conversion, boxing conversion, unboxing conversion, // wrapping conversion, or null type conversion. // //Autodesk.Revit.UI.RibbonPanel rp // = panel as Autodesk.Revit.UI.RibbonPanel; Autodesk.Windows.RibbonPanel rp = panel as Autodesk.Windows.RibbonPanel; Debug.Print(" {0} {1}", panel.ToString(), panel.GetType().Name); foreach (var item in panel.Source.Items) { Autodesk.Windows.RibbonItem ri = item as Autodesk.Windows.RibbonItem; string automationName = ri.AutomationName; Debug.Print(" {0} {1} '{2}' {3}", item.ToString(), item.GetType().Name, automationName, ri.Cookie); } } } } Autodesk.Windows.ComponentManager.ItemExecuted += OnItemExecuted; _subscribed = true; } return(Result.Succeeded); }
protected override bool CanExecute(Autodesk.Windows.RibbonItem parameter) { return(m_CanExecute == null || m_CanExecute()); }
public void PlaceButtonOnModifyRibbon() { try { String SystemTabId = "Modify"; String SystemPanelId = "modify_shr"; adWin.RibbonControl adWinRibbon = adWin.ComponentManager.Ribbon; adWin.RibbonTab adWinSysTab = null; adWin.RibbonPanel adWinSysPanel = null; adWin.RibbonTab adWinApiTab = null; adWin.RibbonPanel adWinApiPanel = null; adWin.RibbonItem adWinApiItem = null; foreach (adWin.RibbonTab ribbonTab in adWinRibbon.Tabs) { // Look for the specified system tab if (ribbonTab.Id == SystemTabId) { adWinSysTab = ribbonTab; foreach (adWin.RibbonPanel ribbonPanel in ribbonTab.Panels) { // Look for the specified panel // within the system tab if (ribbonPanel.Source.Id == SystemPanelId) { adWinSysPanel = ribbonPanel; } } } else { // Look for our API tab if (ribbonTab.Id == myTA.TabName) { adWinApiTab = ribbonTab; foreach (adWin.RibbonPanel ribbonPanel in ribbonTab.Panels) { if (ribbonPanel.Source.Id == "CustomCtrl_%" + myTA.TabName + "%" + myTA.PanelName) { foreach (adWin.RibbonItem ribbonItem in ribbonPanel.Source.Items) { if (ribbonItem.Id == "CustomCtrl_%CustomCtrl_%" + myTA.TabName + "%" + myTA.PanelName + "%" + myTA.Button_01) { adWinApiItem = ribbonItem; } } } if (ribbonPanel.Source.Id == "CustomCtrl_%" + myTA.TabName + "%" + myTA.PanelTransferring) { adWinApiPanel = ribbonPanel; } } } } } if (adWinSysTab != null && adWinSysPanel != null && adWinApiTab != null && adWinApiPanel != null && adWinApiItem != null) { adWinSysTab.Panels.Add(adWinApiPanel); adWinApiPanel.Source.Items.Add(adWinApiItem); adWinApiTab.Panels.Remove(adWinApiPanel); } } #region catch and finally catch (Exception ex) { TaskDialog.Show("me", ex.Message + Environment.NewLine + ex.InnerException); } finally { } #endregion }
void OnApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e) { // Find a system ribbon tab and panel to house // our API items // Also find our API tab, panel and button within // the Autodesk.Windows.RibbonControl context adWin.RibbonControl adWinRibbon = adWin.ComponentManager.Ribbon; adWin.RibbonTab adWinSysTab = null; adWin.RibbonPanel adWinSysPanel = null; adWin.RibbonTab adWinApiTab = null; adWin.RibbonPanel adWinApiPanel = null; adWin.RibbonItem adWinApiItem = null; foreach (adWin.RibbonTab ribbonTab in adWinRibbon.Tabs) { // Look for the specified system tab if (ribbonTab.Id == SystemTabId) { adWinSysTab = ribbonTab; foreach (adWin.RibbonPanel ribbonPanel in ribbonTab.Panels) { // Look for the specified panel // within the system tab if (ribbonPanel.Source.Id == SystemPanelId) { adWinSysPanel = ribbonPanel; } } } else { // Look for our API tab if (ribbonTab.Id == ApiTabName) { adWinApiTab = ribbonTab; foreach (adWin.RibbonPanel ribbonPanel in ribbonTab.Panels) { // Look for our API panel. // The Source.Id property of an API created // ribbon panel has the following format: // CustomCtrl_%[TabName]%[PanelName] // Where PanelName correlates with the string // entered as the name of the panel at creation // The Source.AutomationName property can also // be used as it is also a direct correlation // of the panel name, but without all the cruft // Be sure to include any new line characters // (\n) used for the panel name at creation as // they still form part of the Id & AutomationName //if(ribbonPanel.Source.AutomationName // == ApiPanelName) // Alternative method if (ribbonPanel.Source.Id == "CustomCtrl_%" + ApiTabName + "%" + ApiPanelName) { adWinApiPanel = ribbonPanel; foreach (adWin.RibbonItem ribbonItem in ribbonPanel.Source.Items) { // Look for our command button // The Id property of an API created ribbon // item has the following format: // CustomCtrl_%CustomCtrl_%[TabName]%[PanelName]%[ItemName] // Where ItemName correlates with the string // entered as the first parameter (name) // of the PushButtonData() constructor // While AutomationName correlates with // the string entered as the second // parameter (text) of the PushButtonData() // constructor // Be sure to include any new line // characters (\n) used for the button // name and text at creation as they // still form part of the ItemName // & AutomationName //if(ribbonItem.AutomationName // == ApiButtonText) // alternative method if (ribbonItem.Id == "CustomCtrl_%CustomCtrl_%" + ApiTabName + "%" + ApiPanelName + "%" + ApiButtonName) { adWinApiItem = ribbonItem; } } } } } } } // Make sure we got everything we need if (adWinSysTab != null && adWinSysPanel != null && adWinApiTab != null && adWinApiPanel != null && adWinApiItem != null) { // First we'll add the whole panel including // the button to the system tab adWinSysTab.Panels.Add(adWinApiPanel); // now lets also add the button itself // to a system panel adWinSysPanel.Source.Items.Add(adWinApiItem); // Remove panel from original API tab // It can also be left there if needed, // there doesn't seem to be any problems with // duplicate panels / buttons on seperate tabs // / panels respectively adWinApiTab.Panels.Remove(adWinApiPanel); // Remove our original API tab from the ribbon adWinRibbon.Tabs.Remove(adWinApiTab); } // A new panel should now be added to the // specified system tab. Its command buttons // will behave as they normally would, including // API access and ExternalCommandAvailability tests. // There will also be a second copy of the command // button from the panel added to the specified // system panel. }
protected override bool CanExecute(Autodesk.Windows.RibbonItem parameter) { return(true); }
public adWin.RibbonItem AdwinButton(string tabName, string panelName, string btnName, bool isSystemTab = false) { adWin.RibbonControl adWinRibbon = adWin.ComponentManager.Ribbon; adWin.RibbonTab adWinSysTab = null; adWin.RibbonPanel adWinSysPanel = null; adWin.RibbonTab adWinApiTab = null; adWin.RibbonPanel adWinApiPanel = null; adWin.RibbonItem adWinApiItem = null; //If input tab is system tab if (isSystemTab) { foreach (adWin.RibbonTab ribbonTab in adWinRibbon.Tabs) { if (ribbonTab.Id != tabName) { continue; } adWinSysTab = ribbonTab; break; } if (adWinSysTab != null) { foreach (adWin.RibbonPanel ribbonPanel in adWinApiTab.Panels) { if (ribbonPanel.Source.Id != tabName) { continue; } adWinSysPanel = ribbonPanel; break;; } } return(null); } //If input tab is not a system tab foreach (adWin.RibbonTab ribbonTab in adWinRibbon.Tabs) { if (!ribbonTab.Title.Equals(tabName)) { continue; } adWinApiTab = ribbonTab; adWinApiTab.IsVisible = false; break; } // Problem: Autodesk.Windows.RibbonTab.Panels = {0} ??? // I don't understand here if (adWinApiTab != null) { foreach (adWin.RibbonPanel ribbonPanel in adWinApiTab.Panels) { // Look for our API panel. // The ConvertToPushButton.Id property of an API created // ribbon panel has the following format: // CustomCtrl_%[TabName]%[PanelName] if (ribbonPanel.Source.Id != "CustomCtrl_%" + tabName + "%" + panelName) { continue; } adWinApiPanel = ribbonPanel; break;; } } if (adWinApiPanel != null) { foreach (adWin.RibbonItem ribbonItem in adWinApiPanel.Source.Items) { // Look for our command button // The Id property of an API created ribbon // item has the following format: // CustomCtrl_%CustomCtrl_%[TabName]%[PanelName]%[ItemName] //if(ribbonItem.AutomationName // == ApiButtonText) // alternative method if (ribbonItem.Id != "CustomCtrl_%CustomCtrl_%" + tabName + "%" + panelName + "%" + btnName) { continue; } adWinApiItem = ribbonItem; break; } } if (adWinApiItem != null) { adWinApiItem.ToolTip = "This button is found by api."; TaskDialog.Show("Existing Button", $"Button {btnName} founded"); // Do something return(adWinApiItem); } TaskDialog.Show("Existing Button", $"Button {btnName} is not founded"); return(null); }