By Xiaodong Liang
We got a question on the forum. The customer has a custom ribbon tab on the Assembly and ZeroDoc ribbons, those have panels and buttons.The custom buttons have OnExecute event that can have custom actions added. But Inventor API does not provide the ability to intercept the event when user is clicking on the ribbon tab.
Currently all Autodesk products use the same core of ribbon (AIR Look), which provides some underlying API to get access to that notification. You would need to reference the AdWindows.dll in order to use that code. AdWindows.dll can be found at <Inventor Installation Path>\bin
The following is the code snippet of a plugin.
using Autodesk.Windows;
public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
{
// Initialize AddIn members.
m_inventorApplication = addInSiteObject.Application;
//delegate the event when the ribbon is initialized
Autodesk.Windows.ComponentManager.ItemInitialized +=
new EventHandler<RibbonItemEventArgs>(
ComponentManager_ItemInitialized);
}
//delegate the tab event when the ribbon is initialized
void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
//now one Ribbon item is initialized, but the Ribbon control
//may not be available yet, so check before
if (Autodesk.Windows.ComponentManager.Ribbon != null)
{
foreach (Autodesk.Windows.RibbonTab Tab in Autodesk.Windows.ComponentManager.Ribbon.Tabs)
{
if (Tab.Id == "id_TabTools")
{
Tab.Activated += new EventHandler(Tab_Activated);
}
}
//and remove the event handler
Autodesk.Windows.ComponentManager.ItemInitialized -=
new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
}
// when the tab is activated
void Tab_Activated(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show(
"Tab " + ComponentManager.Ribbon.ActiveTab.Id + " Activated!");
}