Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor Ribbon Buttons and Event Handlers

0 REPLIES 0
Reply
Message 1 of 1
Blarran
1052 Views, 0 Replies

Inventor Ribbon Buttons and Event Handlers

Is there a way to hook into the Inventor ribbon buttons (not custom) to monitor a click event?

 

What I would like to do is kick off a job to the job processor when a user checks a file into Vault. The job is for creating a DXF file of a sheet metal part. I'm not sure if launching a job when file is checked into vault is the right approach. Seems overkill but apparently DXF files are not getting produced. Open to other suggestions.

 

I came across an article on the Manufacturing DevBlog  "Intercept click event on ribbon tab":

http://adndevblog.typepad.com/manufacturing/2013/02/intercept-click-event-on-a-ribbon-tab.html

 

The example code  sets up an event listener to monitor the click event for the "Tools" tab. I modified the code to monitor the event for when the "Vault" tab (or id_TabVault) is clicked but for some reason the event handler is never triggered. The other tabs like "Tools" and "Getting Started" can trigger the event handler. See code below.

 

But even if I could get to the Vaults tab, how would I set up the event handler for the Check-In button? Is this possible?

Thanks

 

 

using System;
using System.Runtime.InteropServices;
using System.Windows;
using Autodesk.Windows;
using Inventor;
using Microsoft.Win32;
using System.Diagnostics;
namespace InventorCheckinAddIn
{
    /// <summary>
    /// This is the primary AddIn Server class that implements the ApplicationAddInServer interface
    /// that all Inventor AddIns are required to implement. The communication between Inventor and
    /// the AddIn is via the methods on this interface.
    /// </summary>
    [GuidAttribute("30887386-a1a2-4b90-b497-316e2e3e995a")]
    public class StandardAddInServer : Inventor.ApplicationAddInServer
    {

        private Inventor.UserInterfaceEvents uiEvents;
        // Inventor application object.
        private Inventor.Application m_inventorApplication;

        public StandardAddInServer()
        {
        }

        #region ApplicationAddInServer Members

        public void Activate(Inventor.ApplicationAddInSite addInSiteObject, bool firstTime)
        {
            // This method is called by Inventor when it loads the addin.
            // The AddInSiteObject provides access to the Inventor Application object.
            // The FirstTime flag indicates if the addin is loaded for the first time.

            // Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application;

            //delegate the event when the ribbon is initialized
            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)
                {
                    
                    if (Tab.Id == "id_TabVault" || Tab.Id == "id_GetStarted" || 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)
        {
            // *** THE Tab_Activated NEVER SEES THE VAULT TAB CLICK EVENT ***
            System.Windows.Forms.MessageBox.Show(
                "Tab " + ComponentManager.Ribbon.ActiveTab.Id + " Activated!");
        }


        public void Deactivate()
        {
            // This method is called by Inventor when the AddIn is unloaded.
            // The AddIn will be unloaded either manually by the user or
            // when the Inventor session is terminated

            // TODO: Add ApplicationAddInServer.Deactivate implementation

            // Release objects.
            Marshal.ReleaseComObject(m_inventorApplication);
            m_inventorApplication = null;

            GC.WaitForPendingFinalizers();
            GC.Collect();
        }

        public void ExecuteCommand(int commandID)
        {
            // Note:this method is now obsolete, you should use the 
            // ControlDefinition functionality for implementing commands.
        }

        public object Automation
        {
            // This property is provided to allow the AddIn to expose an API 
            // of its own to other programs. Typically, this  would be done by
            // implementing the AddIn's API interface in a class and returning 
            // that class object through this property.

            get
            {
                // TODO: Add ApplicationAddInServer.Automation getter implementation
                return null;
            }
        }

        #endregion

    }
}

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report