Addin OnCommand event duplicated call

hi,

I've built a small add in.

It "works" yet I see a duplicated call when user clicks on menu..

The function AddInOnCommandClick is called with the correct bottom number twice for each click..

Any ideas why?

 

relevant code below:

 

 

 public void OnConnection(object Application, SolidEdgeFramework.SeConnectMode ConnectMode, SolidEdgeFramework.AddIn AddInInstance)

        {

            // Store local variables for later use

            m_addin = AddInInstance;

            m_application = (SolidEdgeFramework.Application)Application;

            // Set Addin's GUI Version

            AddInInstance.GuiVersion = 1;

 

        }

 

public void OnConnectToEnvironment(string EnvCatID, object pEnvironmentDispatch, bool bFirstTime)

        {

            try

            {

                string[] commandNames = new string[3];

                commandNames[0] = "cmdAbout\n\nAbout System\nAbout";

                commandNames[1] = "cmdDuplicateFile\n\nDuplicate File\nDuplicate";

                commandNames[2] = "cmdTester\n\nTester \nDebug";

 

                int[] commandIDs = new int[3];

                commandIDs[0] = 101;

                commandIDs[1] = 102;

                commandIDs[2] = 103;

 

               addinEvents = m_addin.AddInEvents;

               addinEvents.OnCommand += new             SolidEdgeFramework.DISEAddInEvents_OnCommandEventHandler(AddInOnCommandClick);

 

                m_addin.SetAddInInfo(Marshal.GetHINSTANCE(this.GetType().Module).ToInt32(), EnvCatID, "ManagedMenu", 1, 2, 1, 2, commandIDs.Length, commandNames, commandIDs);

 

                if (bFirstTime)

                {

                    SolidEdgeFramework.Environment env = (SolidEdgeFramework.Environment)pEnvironmentDispatch;

                    env.CommandBars.Add("ManagedMenu",SolidEdgeFramework.SeBarPosition.seBarTop); //false, false);

 

                    m_addin.AddCommandBarButton(EnvCatID, "ManagedMenu", 101);

                    m_addin.AddCommandBarButton(EnvCatID, "ManagedMenu", 102);

                    m_addin.AddCommandBarButton(EnvCatID, "ManagedMenu", 103);

 

                }

            }

            catch (System.Exception ex)

            {

                Console.WriteLine(ex.Message);

            }

        }

 

 

Posted by: joseph polk
Post date: 1/30/2012 9:14:39 AM

2 REPLIES
Highlighted

RE: Addin OnCommand event duplicated call

I think you should put these lines

=====================

addinEvents = m_addin.AddInEvents;

addinEvents.OnCommand += new SolidEdgeFramework.DISEAddInEvents_OnCommandEventHandler(AddInOnCommandClick);

 

in the OnConnection after these lines of code

===========================

// Store local variables for later use

m_addin = AddInInstance;

m_application = (SolidEdgeFramework.Application)Application;

 

the addinEvents.OnCommand seems to be mapped multiple times since OnConnectToEnvironment event will be called multiple times

 

then it would be set only once .. that's what I think

 

Posted by: David Shooner
Post date: 1/31/2012 8:27:40 AM

RE: Addin OnCommand event duplicated call

Yep.

Thank you

 

 

Posted by: joseph polk
Post date: 1/31/2012 11:27:15 AM