Detecting Tab Activated Event in the Ribbon

By Philippe Leefsma

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!");

<

p style=”line-height: normal;margin: 0in 0in 0pt” class=”MsoNormal”>}


Comments

3 responses to “Detecting Tab Activated Event in the Ribbon”

  1. Hi Philippe – I guess there’s no way to use this from native code?
    Thanks, jeff

  2. Hi Jeff,
    The Ribbon API is .Net only, so there is no way to access it from C++.

  3. Hi, Phil,
    I have an addin in VB.NET. Can you help to have a VB.NET version of this code. Thank you so much!
    Limin

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading