1 Reply Latest reply on Dec 7, 2016 4:31 AM by Win Lai

    how to AddMenuItem in SW2015

    Win Lai

      dear all,

      I have some question need you help.

      when I use "AddMenuItem4" inSolidWorks2015 ,and the SolidWorks crash when run the code:

       

      menu = iSwApp.AddMenuItem4(swDocumentTypes_e.swDocPART, Cookie, "NewMenu", 0, "callback", 1, "tip", "")

       

      The code modify from SolidWorks2015 API SDK as bollow :

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

          Function ConnectToSW(ByVal ThisSW As Object, ByVal Cookie As Integer) As Boolean Implements SolidWorks.Interop.swpublished.SwAddin.ConnectToSW

              iSwApp = ThisSW

              addinID = Cookie

       

       

              Dim menu As Boolean

              menu = iSwApp.AddMenuItem4(swDocumentTypes_e.swDocPART, Cookie, "NewMenu", 0, "callback", 1, "tip", "")

       

       

              ' Setup callbacks

              iSwApp.SetAddinCallbackInfo(0, Me, addinID)

       

       

              ' Setup the Command Manager

              iCmdMgr = iSwApp.GetCommandManager(Cookie)

              AddCommandMgr()

       

       

              'Setup the Event Handlers

              SwEventPtr = iSwApp

              openDocs = New Hashtable

              AttachEventHandlers()

       

       

              'Setup Sample Property Manager

              AddPMP()

       

       

              ConnectToSW = True

          End Function

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

       

      thank you very much!!!

        • Re: how to AddMenuItem in SW2015
          Win Lai

          change the :

                  Dim menu As Boolean

                  menu = iSwApp.AddMenuItem4(swDocumentTypes_e.swDocPART, Cookie, "NewMenu", 0, "callback", 1, "tip", "")

          to:

                  iSwApp.AddMenu(swDocumentTypes_e.swDocPART, "NewMenu", 4)

                  iSwApp.AddMenuItem2(swDocumentTypes_e.swDocPART, Cookie, "New(&N)@NewMenu", 0, "OnNewPartDoc", "", "CreateNewPart")

           

          Is OK now.