5 Replies Latest reply on Feb 19, 2016 11:19 AM by Sdiri Marwa

    New Addin Icon

    Chris Champions

      I tried to modify the sub from the Addin Template - see the code below

      it's working fine with 3 items shown on the drop-down menu, however, only 2 icons are shown on the FM - what I'm missing here

      Any help, please

       

       

      Capture.PNG

       

       

       

      Public Sub AddCommandMgr()

       

       

              Dim cmdGroup As ICommandGroup

       

       

              If iBmp Is Nothing Then

                  iBmp = New BitmapHandler()

              End If

       

       

              Dim thisAssembly As Assembly

       

       

              Dim cmdIndex0 As Integer, cmdIndex1 As Integer, cmdIndex2 As Integer 'Add new cmdIndex2

              Dim Title As String = "VB Addin1"

              Dim ToolTip As String = "VB Addin1"

       

       

       

       

              Dim docTypes() As Integer = {swDocumentTypes_e.swDocASSEMBLY, _

                                             swDocumentTypes_e.swDocDRAWING, _

                                             swDocumentTypes_e.swDocPART}

       

       

              thisAssembly = System.Reflection.Assembly.GetAssembly(Me.GetType())

       

       

              Dim cmdGroupErr As Integer = 0

              Dim ignorePrevious As Boolean = False

       

       

              Dim registryIDs As Object = Nothing

              Dim getDataResult As Boolean = iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, registryIDs)

       

       

              Dim knownIDs As Integer() = New Integer(2) {mainItemID1, mainItemID2, mainItemID3}

       

       

              If getDataResult Then

                  If Not CompareIDs(registryIDs, knownIDs) Then 'if the IDs don't match, reset the commandGroup

                      ignorePrevious = True

                  End If

              End If

       

       

              cmdGroup = iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, cmdGroupErr)

              If cmdGroup Is Nothing Or thisAssembly Is Nothing Then

                  Throw New NullReferenceException()

              End If

       

       

       

       

       

       

              cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("Test1.ToolbarLarge.bmp", thisAssembly)

              cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("Test1.ToolbarSmall.bmp", thisAssembly)

              cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("Test1.MainIconLarge.bmp", thisAssembly)

              cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("Test1.MainIconSmall.bmp", thisAssembly)

       

       

              Dim menuToolbarOption As Integer = swCommandItemType_e.swMenuItem Or swCommandItemType_e.swToolbarItem

       

       

              cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption)

              cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "PMPEnable", mainItemID2, menuToolbarOption)

              cmdIndex2 = cmdGroup.AddCommandItem2("NewItemName", -1, "NewItemHintString", "ToolTip", 0, "NewItemCallBackFunction", "", mainItemID3, menuToolbarOption)

       

       

       

       

       

       

       

       

              cmdGroup.HasToolbar = True

              cmdGroup.HasMenu = True

              cmdGroup.Activate()

       

       

              Dim flyGroup As FlyoutGroup

              flyGroup = iCmdMgr.CreateFlyoutGroup(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint", _

                    cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, cmdGroup.LargeIconList, "FlyoutCallback", "FlyoutEnable")

       

       

              flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1")

       

       

              flyGroup.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

       

       

       

       

              For Each docType As Integer In docTypes

                  Dim cmdTab As ICommandTab = iCmdMgr.GetCommandTab(docType, Title)

                  Dim bResult As Boolean

       

       

                  If Not cmdTab Is Nothing And Not getDataResult Or ignorePrevious Then 'if tab exists, but we have ignored the registry info, re-create the tab.  Otherwise the ids won't matchup and the tab will be blank

                      Dim res As Boolean = iCmdMgr.RemoveCommandTab(cmdTab)

                      cmdTab = Nothing

                  End If

       

       

                  If cmdTab Is Nothing Then

                      cmdTab = iCmdMgr.AddCommandTab(docType, Title)

       

       

                      Dim cmdBox As CommandTabBox = cmdTab.AddCommandTabBox

       

       

                      Dim cmdIDs(3) As Integer

                      Dim TextType(3) As Integer

       

       

                      cmdIDs(0) = cmdGroup.CommandID(cmdIndex0)

                      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

       

       

                      cmdIDs(1) = cmdGroup.CommandID(cmdIndex1)

                      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

       

       

                      cmdIDs(2) = cmdGroup.ToolbarId

                      TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal

       

       

       

       

                      bResult = cmdBox.AddCommands(cmdIDs, TextType)

       

       

                      Dim cmdBox1 As CommandTabBox = cmdTab.AddCommandTabBox()

                      ReDim cmdIDs(1)

                      ReDim TextType(1)

       

       

                      cmdIDs(0) = flyGroup.CmdID

                      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

       

                      bResult = cmdBox1.AddCommands(cmdIDs, TextType)

       

       

                      cmdTab.AddSeparator(cmdBox1, cmdIDs(0))

       

       

                  End If

              Next

       

       

              thisAssembly = Nothing

       

       

          End Sub

        • Re: New Addin Icon
          Artem Taturevych

          Delete you tab box from SolidWorks and let add-in to recreate it. I think this is just a caching issue.

           

          RMB in the command bar->Customize->Then

          del.png

          • Re: New Addin Icon
            Sdiri Marwa

            Hi,

            Based on this image

            Capture.JPG

            and this code

            cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption)

                    cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "PMPEnable", mainItemID2, menuToolbarOption)

                    cmdIndex2 = cmdGroup.AddCommandItem2("NewItemName", -1, "NewItemHintString", "ToolTip", 0, "NewItemCallBackFunction", "", mainItemID3, menuToolbarOption)

            i think that 0,2,0 is the one causing the image repetition and as defined in this link 2015 SOLIDWORKS API Help - AddCommandItem2 Method (ICommandGroup)  this prameter is the image index .Try to give 0,1,2 as input to image index parameter in each of the instruction.

            • Re: New Addin Icon
              Sdiri Marwa

              Hi

              I think know it is MenuTBOption parameter in the same link .For example if you write this

                cmdGroup = iCmdMgr.CreateCommandGroup(1, Title, ToolTip, "", -1);

                          cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.ToolbarLarge.bmp", thisAssembly);

                          cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.ToolbarSmall.bmp", thisAssembly);

                          cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.MainIconLarge.bmp", thisAssembly);

                          cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("DotNetControlsDemo.MainIconSmall.bmp", thisAssembly);

               

               

                          cmdIndex0 = cmdGroup.AddCommandItem("WinFromInTaskPane", -1, "Add Windows Form In Task Pane", "WinFormInTaskPane", 0, "WinFormInTaskPane", "EnableWinFormInTaskPane", 0);

                          cmdIndex1 = cmdGroup.AddCommandItem("UserControlInModelView", -1, "Add User Control In Model View", "UserControlInModelView", 1, "UserControlInModelView", "EnableUserControlInModelView", 1);

                          cmdIndex2 = cmdGroup.AddCommandItem("WPFInModelView", -1, "Add WPF In ModelView", "WPFInModelView", 2, "WPFInModelView", "EnableWPFInModelView", 2);

                          cmdIndex3 = cmdGroup.AddCommandItem("WinFormInFeatureMgr", -1, "Add Windows Form In FeatureManager design tree", "WinFormInFeatureMgr", 3, "WinFormInFeatureMgr", "EnableWinFormInFeatureMgr", 3);

                          cmdIndex4 = cmdGroup.AddCommandItem("Show PMP", -1, "Display PropertyManager page with .NET Controls", "Show PMP", 4, "ShowPMP", "EnablePMP", 4);

               

               

                          cmdGroup.HasToolbar = true;

                          cmdGroup.HasMenu = true;

                          cmdGroup.Activate();

              you will have this interface.

              1. I hope this help you PS: i can send you the example for help but i dont know how to attach the example rar here