Menu gone lost

Valued Contributor
Valued Contributor

Hi,

I've followed the steps in http://www.jasonnewell.net/Community/Forums/tabid/55/aft/163/Default.aspx

When Solid Edge starts I can see my menu but when I'm opening a file it's lost - what am I missing?

my C#:

 

using Microsoft.Win32;

using System;

using System.Reflection;

using System.Runtime.InteropServices;

namespace MyAddIn

{

    [GuidAttribute("2A24FC8D-36EE-4967-BAA0-22E584B9149B"),

    ProgId("MyAddIn.Addin"),

    ComVisible(true)]

    public class AddIn : SolidEdgeFramework.ISolidEdgeAddIn

    {

        private SolidEdgeFramework.AddIn m_addin;

        private SolidEdgeFramework.Application m_application;

 

        public AddIn()

        {

        }

 

        #region ISolidEdgeAddIn Members

 

        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;

 

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

            }

        }

 

        public void OnDisconnection(SolidEdgeFramework.SeDisconnectMode DisconnectMode)

        {

            if (m_addin != null)

            {

                Marshal.ReleaseComObject(m_addin);

                m_addin = null;

            }

            if (m_application != null)

            {

                Marshal.ReleaseComObject(m_application);

                m_application = null;

            }

        }

 

        #endregion

 

        #region "Regasm.exe functions"

        // Called by Regasm.exe

        [ComRegisterFunctionAttribute()]

        static void RegisterServer(Type t)

        {

            RegistryKey baseKey = null;

            RegistryKey summaryKey = null;

            AssemblyTitleAttribute titleAttribute = null;

            AssemblyDescriptionAttribute descriptionAttribute = null;

            try

            {

                baseKey = Registry.ClassesRoot.CreateSubKey(

                @"CLSID\{" + t.GUID.ToString() + "}");

                if (baseKey != null)

                {

                    // Tell Solid Edge to automatically load your addin

                    baseKey.SetValue("AutoConnect", 1);

                    // Write title

                    if (t.Assembly.IsDefined(typeof(AssemblyTitleAttribute), true))

                    {

                        titleAttribute = (AssemblyTitleAttribute)

                        AssemblyTitleAttribute.GetCustomAttribute(

                        t.Assembly, typeof(AssemblyTitleAttribute));

                        baseKey.SetValue("409", titleAttribute.Title);

                    }

                    // Write description

                    if (t.Assembly.IsDefined(typeof(AssemblyDescriptionAttribute), true))

                    {

                        descriptionAttribute = (AssemblyDescriptionAttribute)

                        AssemblyDescriptionAttribute.GetCustomAttribute(

                        t.Assembly, typeof(AssemblyDescriptionAttribute));

                        summaryKey = baseKey.CreateSubKey("Summary");

                        summaryKey.SetValue("409", descriptionAttribute.Description);

                    }

                    // Write required registry entries for a Solid Edge Addin

                    // See secatids.h in C:\Program Files\Solid Edge VXX\SDK\include

                    // CATID_SolidEdgeAddIn                      

                    baseKey.CreateSubKey(@"Implemented Categories\{26B1D2D1-2B03-11d2-B589-080036E8B802}");

                    // Specify the Environment Categories that you want you addin

                    // to work in

                    // CATID_SEApplication

                    baseKey.CreateSubKey(@"Environment Categories\{26618394-09D6-11d1-BA07-080036230602}");

                    // CATID_SEPart

                    baseKey.CreateSubKey(@"Environment Categories\{26618396-09D6-11d1-BA07-080036230602}");

                }

            }

            catch

            {

            }

            finally

            {

                if (baseKey != null)

                {

                    baseKey.Close();

                }

                if (baseKey != null)

                {

                    baseKey.Close();

                }

            }

        }

 

        // Here we cleanup any registry values left from Regasm /u.

        [ComUnregisterFunctionAttribute()]

        static void UnregisterServer(Type t)

        {

            try

            {

                Registry.ClassesRoot.DeleteSubKeyTree(@"CLSID\{" + t.GUID.ToString() + "}");

            }

            catch

            {

            }

        }

 

        #endregion

    }

}

 

 

Posted by: joseph polk
Post date: 1/18/2012 12:29:08 PM

1 REPLY

RE: Menu gone lost

Valued Contributor
Valued Contributor

Well I had no idea bout the registry when posted this...

The code is fine for more environments add their appropriate string from the

\SDK\Include\secatids.h

 

and at the end of RegisterServer func:

baseKey.CreateSubKey(@"Environment Categories\{26618395-09D6-11d1-BA07-080036230602}"); // the CATID_SEAssemblys for Assemblies enviroment

 

Posted by: joseph polk
Post date: 1/31/2012 11:36:16 AM