I was recently working on an ADN case where the developer wanted to react to his custom tab being activated. The Inventor Ribbon API itself doesn’t provide this kind of notification, however the underlying Ribbon API does.
You need to add a reference to AdWindows.dll (located in Inventor Bin install folder) to your .Net project in order to compile that code:
//Your Add-In activate method, for example
public void Activate(
ApplicationAddInSite addInSiteObject,
bool firstTime)
{
Autodesk.Windows.ComponentManager.ItemInitialized
+= new EventHandler<RibbonItemEventArgs>(
ComponentManager_ItemInitialized);
}
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)
{
// Replace with the id of the target tab
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);
}
}
void Tab_Activated(object sender, EventArgs e)
{
System.Windows.Forms.MessageBox.Show(
"Tab " + ComponentManager.Ribbon.ActiveTab.Id
+ " Activated!");
}