1 Reply Latest reply on Aug 19, 2015 3:26 PM by Andrew Johnson

    Setting up toolbars and menus

    Greg Johnson

      I have added quite a few commands in my addin and the toolbar and menu has become very difficult to manage. Does anyone have any recommendations on a way to add new commands to the addin without having to spend significant time rewriting the code that controls the toolbar and menu. I'm looking for a better way than I doing this today. I have attached the code below.

       

      Regards,

       

      Greg Johnson

      Vermeer Corporation

       

          Public Sub AddCommandMgr()

              'Standard variables

              Dim Title As String = "Vermeer Tools"

              Dim ToolTip As String = "Vermeer Tools for SolidWorks"

              Dim docTypes() As Integer = {swDocumentTypes_e.swDocASSEMBLY, swDocumentTypes_e.swDocDRAWING, swDocumentTypes_e.swDocPART}

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

       

              Try

      Dim cmdGroup As ICommandGroup

      Dim cmdGroup2 As ICommandGroup

      Dim cmdGroup3 As ICommandGroup

      Dim cmdGroup4 As ICommandGroup

      Dim cmdGroup5 As ICommandGroup

      Dim cmdGroup6 As ICommandGroup

      Dim cmdGroup7 As ICommandGroup

      Dim cmdGroup8 As ICommandGroup

       

      If iBmp Is Nothing Then

      iBmp = New BitmapHandler()

      End If

       

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

       

      Dim cmdGroupErr As Integer = 0

      Dim ignorePrevious As Boolean = False

       

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

      If cmdGroup Is Nothing Or thisAssembly Is Nothing Then

      Throw New NullReferenceException()

      End If

       

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

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

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

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

       

       

      '*********************************************************************************************************************

       

      Dim registryIDs As Object = Nothing

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

       

      Dim knownIDs As Integer() = New Integer(44) {mainItemID1, mainItemID2, mainItemID3, mainItemID4, mainItemID5, mainItemID6, mainItemID7, mainItemID8, mainItemID9, mainItemID10, mainItemID11, mainItemID12, mainItemID13, mainItemID14, mainItemID15, mainItemID16, mainItemID17, mainItemID18, mainItemID19, mainItemID20, mainItemID21, mainItemID22, mainItemID23, mainItemID24, mainItemID25, mainItemID26, mainItemID27, mainItemID28, mainItemID29, mainItemID30, mainItemID31, mainItemID32, mainItemID33, mainItemID34, mainItemID35, mainItemID36, mainItemID37, mainItemID38, mainItemID39, mainItemID40, mainItemID41, mainItemID42, mainItemID43, mainItemID44, mainItemID45}

       

      If getDataResult Then

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

      ignorePrevious = True

      End If

      End If

       

      ' Pull-down menu setup

       

      Dim cmdIndex0 As Integer = cmdGroup.AddCommandItem2("VMC - Custom Properties", -1, "Custom Properties", "VMC - Custom Properties", 0, "VMC", "", mainItemID1, menuToolbarOption)

      Dim cmdIndex10 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdIndex24 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdIndex15 As Integer = cmdGroup.AddCommandItem2("New Drawing", -1, "New Drawing", "New Drawing", 17, "NewDrawing", "", mainItemID14, menuToolbarOption)

      Dim cmdIndex22 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdIndex23 As Integer = cmdGroup.AddCommandItem2("Common Notes", -1, "Common Notes", "Common Notes", 21, "CommonNotes", "", mainItemID21, menuToolbarOption)

      Dim cmdIndex31 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdIndex34 As Integer = cmdGroup.AddCommandItem2("Increment UP", -1, "Increment UP", "Increment UP", 32, "IncrementUP", "", mainItemID29, menuToolbarOption)

      Dim cmdIndex35 As Integer = cmdGroup.AddCommandItem2("Increment DOWN", -1, "Increment DOWN", "Increment DOWN", 33, "IncrementDOWN", "", mainItemID30, menuToolbarOption)

      Dim cmdIndex36 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdIndex33 As Integer = cmdGroup.AddCommandItem2("DXF Maker", -1, "DXF Maker", "DXF Maker", 7, "DXFMaker", "", mainItemID28, menuToolbarOption)

      Dim cmdIndex32 As Integer = cmdGroup.AddCommandItem2("Bar Stock", -1, "Bar Stock", "Bar Stock", 6, "BarStock", "", mainItemID27, menuToolbarOption)

      Dim cmdindex46 As Integer = cmdGroup.AddCommandItem2("Bolt/Nut", -1, "Bolt/Nut", "Bolt/Nut", 34, "BoltNut", "", mainItemID40, menuToolbarOption)

      Dim cmdindex51 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdindex47 As Integer = cmdGroup.AddSpacer2(-1, menuToolbarOption)

      Dim cmdindex52 As Integer = cmdGroup.AddCommandItem2("Options", -1, "Options", "Options", 46, "Options", "", mainItemID44, menuToolbarOption)

      Dim cmdindex53 As Integer = cmdGroup.AddCommandItem2("About Vermeer Tools", -1, "About Vermeer Tools", "About Vermeer Tools", 46, "AboutVermeerTools", "", mainItemID45, menuToolbarOption)

       

      cmdGroup.HasToolbar = True

      cmdGroup.HasMenu = True

      cmdGroup.Activate()

       

      ' Properties Sub Menu

      Dim subMenuTitle As String = String.Format("{0}\\Custom Property Tools", Title)

      cmdGroup2 = iCmdMgr.CreateCommandGroup2(cmdGroupID2, subMenuTitle, "Custom Properties Tools", "", 1, ignorePrevious, cmdGroupErr)

      cmdGroup2.HasToolbar = True

      cmdGroup2.HasMenu = True

      cmdGroup2.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypePART + swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY + swDocTemplateTypes_e.swDocTemplateTypeDRAWING

       

      cmdGroup2.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup2.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup2.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

      cmdGroup2.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdIndex1 As Integer = cmdGroup2.AddCommandItem2("Prop Copy", 0, "Prop Copy", "Prop Copy", 9, "PropCopy", "", mainItemID2, menuToolbarOption)

      Dim cmdIndex2 As Integer = cmdGroup2.AddCommandItem2("Revision Delete", 1, "Revision Delete", "Revision Delete", 8, "RevisionDelete", "", mainItemID3, menuToolbarOption)

      Dim cmdindex48 As Integer = cmdGroup2.AddCommandItem2("Revision Updater", 2, "Revision Updater", "Revision Updater", 35, "RevisionUpdater", "", mainItemID41, menuToolbarOption)

       

       

      cmdGroup2.Activate()

       

      ' Colors Sub Menu

      subMenuTitle = String.Format("{0}\\Colors", Title)

      cmdGroup3 = iCmdMgr.CreateCommandGroup2(cmdGroupID3, subMenuTitle, "Colors", "", 3, ignorePrevious, cmdGroupErr)

      cmdGroup3.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypePART + swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY

       

      cmdGroup3.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup3.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup3.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

      cmdGroup3.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdIndex3 As Integer = cmdGroup3.AddCommandItem2("Random Color", 0, "Random Color", "Random Color", 23, "RandomColor", "", mainItemID4, menuToolbarOption)

      Dim cmdIndex4 As Integer = cmdGroup3.AddCommandItem2("Vermeer Yellow", 1, "Vermeer Yellow", "Vermeer Yellow", 24, "VermeerYellow", "", mainItemID5, menuToolbarOption)

      Dim cmdIndex5 As Integer = cmdGroup3.AddCommandItem2("Vermeer Black", 2, "Vermeer Black", "Vermeer Black", 25, "VermeerBlack", "", mainItemID6, menuToolbarOption)

      Dim cmdIndex6 As Integer = cmdGroup3.AddCommandItem2("Vermeer Green", 3, "Vermeer Green", "Vermeer Green", 26, "VermeerGreen", "", mainItemID7, menuToolbarOption)

      Dim cmdIndex7 As Integer = cmdGroup3.AddCommandItem2("Vermeer White", 4, "Vermeer White", "Vermeer White", 27, "VermeerWhite", "", mainItemID8, menuToolbarOption)

      Dim cmdIndex8 As Integer = cmdGroup3.AddCommandItem2("Clear Zinc", 5, "Clear Zinc", "Clear Zinc", 47, "ClearZinc", "", mainItemID9, menuToolbarOption)

      Dim cmdIndex9 As Integer = cmdGroup3.AddCommandItem2("Yellow Zinc", 6, "Yellow Zinc", "Yellow Zinc", 48, "YellowZinc", "", mainItemID10, menuToolbarOption)

       

      cmdGroup3.HasToolbar = True

      cmdGroup3.HasMenu = True

      cmdGroup3.Activate()

       

      ' Views Sub Menu

      subMenuTitle = String.Format("{0}\\Views", Title)

      cmdGroup4 = iCmdMgr.CreateCommandGroup2(cmdGroupID4, subMenuTitle, "Colors", "", 18, ignorePrevious, cmdGroupErr)

      cmdGroup4.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypePART + swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY + swDocTemplateTypes_e.swDocTemplateTypeDRAWING

       

      cmdGroup4.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup4.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup4.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

      cmdGroup4.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdIndex37 As Integer = cmdGroup4.AddCommandItem2("Front View/Lower Center", 0, "Front View/Lower Center", "Front View/Lower Center", 36, "TWO", "", mainItemID31, swCommandItemType_e.swMenuItem)

      Dim cmdIndex38 As Integer = cmdGroup4.AddCommandItem2("Back View/Upper Center", 1, "Back View/Upper Center", "Back View/Upper Center", 37, "EIGHT", "", mainItemID32, swCommandItemType_e.swMenuItem)

      Dim cmdIndex39 As Integer = cmdGroup4.AddCommandItem2("Left View/Middle Left", 2, "Left View/Middle Left", "Left View/Middle Left", 38, "FOUR", "", mainItemID33, swCommandItemType_e.swMenuItem)

      Dim cmdIndex40 As Integer = cmdGroup4.AddCommandItem2("Right View/Middle Right", 3, "Right View/Middle Right", "Right View/Middle Right", 39, "SIX", "", mainItemID34, swCommandItemType_e.swMenuItem)

      Dim cmdIndex41 As Integer = cmdGroup4.AddCommandItem2("Top View/Middle Center", 4, "Top View/Middle Center", "Top View/Middle Center", 40, "FIVE", "", mainItemID35, swCommandItemType_e.swMenuItem)

      Dim cmdIndex42 As Integer = cmdGroup4.AddCommandItem2("Top-Left-Front Iso View/Lower Left", 5, "Top-Left-Front Iso View/Lower Left", "Top-Left-Front Iso View/Lower Left", 41, "ONE", "", mainItemID36, swCommandItemType_e.swMenuItem)

      Dim cmdIndex43 As Integer = cmdGroup4.AddCommandItem2("Top-Right-Front Iso View/Lower Right", 6, "Top-Right-Front Iso View/Lower Right", "Top-Right-Front Iso View/Lower Right", 42, "THREE", "", mainItemID37, swCommandItemType_e.swMenuItem)

      Dim cmdindex44 As Integer = cmdGroup4.AddCommandItem2("Top-Left-Back Iso View/Upper Left", 7, "Top-Left-Back Iso View/Upper Left", "Top-Left-Back Iso View/Upper Left", 44, "SEVEN", "", mainItemID38, swCommandItemType_e.swMenuItem)

      Dim cmdindex45 As Integer = cmdGroup4.AddCommandItem2("Top-Right-Back/Upper Right", 8, "Top-Right-Back/Upper Right", "Top-Right-Back/Upper Right", 43, "NINE", "", mainItemID39, swCommandItemType_e.swMenuItem)

       

      cmdGroup4.HasToolbar = True

      cmdGroup4.HasMenu = True

      cmdGroup4.Activate()

       

      ' Tools Sub Menu

      subMenuTitle = String.Format("{0}\\Tools", Title)

      cmdGroup5 = iCmdMgr.CreateCommandGroup2(cmdGroupID5, subMenuTitle, "Colors", "", 19, ignorePrevious, cmdGroupErr)

      cmdGroup5.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypePART + swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY + swDocTemplateTypes_e.swDocTemplateTypeDRAWING

       

      cmdGroup5.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup5.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup5.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

      cmdGroup5.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdIndex11 As Integer = cmdGroup5.AddCommandItem2("PDM Complete Search", 0, "PDM Complete Search", "PDM Complete Search", 1, "PDMCompleteSearch", "", mainItemID11, menuToolbarOption)

      Dim cmdIndex12 As Integer = cmdGroup5.AddCommandItem2("PDM Addin On/Off", 1, "PDM Addin On/Off", "PDM Addin On/Off", 2, "PDMAddIn", "", mainItemID12, menuToolbarOption)

      Dim cmdIndex13 As Integer = cmdGroup5.AddCommandItem2("Item Link", 2, "Item Link", "Item Link", 3, "ItemLink", "", mainItemID13, menuToolbarOption)

      Dim cmdIndex14 As Integer = cmdGroup5.AddSpacer2(3, menuToolbarOption)

      Dim cmdIndex25 As Integer = cmdGroup5.AddCommandItem2("Coincident", 4, "Coincident", "Coincident", 14, "Coincident", "", mainItemID22, menuToolbarOption)

      Dim cmdIndex26 As Integer = cmdGroup5.AddCommandItem2("Concentric", 5, "Concentric", "Concentric", 15, "Concentric", "", mainItemID23, menuToolbarOption)

      Dim cmdIndex27 As Integer = cmdGroup5.AddCommandItem2("Parallel", 6, "Parallel", "Parallel", 16, "Parallel", "", mainItemID24, menuToolbarOption)

      Dim cmdIndex28 As Integer = cmdGroup5.AddSpacer2(7, menuToolbarOption)

      Dim cmdIndex29 As Integer = cmdGroup5.AddCommandItem2("Tangent Edges", 8, "Tangent Edges", "Tangent Edges", 11, "TangentEdges", "", mainItemID25, menuToolbarOption)

      Dim cmdIndex30 As Integer = cmdGroup5.AddCommandItem2("Flip", 9, "Flip", "Flip", 12, "Flip", "", mainItemID26, menuToolbarOption)

       

      cmdGroup5.HasToolbar = True

      cmdGroup5.HasMenu = True

      cmdGroup5.Activate()

       

      ' BETA Sub Menu

      subMenuTitle = String.Format("{0}\\BETA", Title)

      cmdGroup6 = iCmdMgr.CreateCommandGroup2(cmdGroupID6, subMenuTitle, "Colors", "", 20, ignorePrevious, cmdGroupErr)

      cmdGroup6.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypePART + swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY + swDocTemplateTypes_e.swDocTemplateTypeDRAWING

       

      cmdGroup6.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup6.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup6.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

      cmdGroup6.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdindex49 As Integer = cmdGroup6.AddCommandItem2("Create Configurations BETA", 0, "Create Configurations", "Create Configurations", 45, "CreateConfigurations", "", mainItemID42, menuToolbarOption)

      Dim cmdindex50 As Integer = cmdGroup6.AddCommandItem2("Create Cut View Configuration BETA", 1, "Create Sheet Metal Cut View Configuration", "Create Sheet Metal Cut View Configuration", 45, "CreateCutViewConfiguration", "", mainItemID43, menuToolbarOption)

       

      cmdGroup6.HasToolbar = True

      cmdGroup6.HasMenu = True

      cmdGroup6.Activate()

       

      ' Drawing Tools Sub Menu

      subMenuTitle = String.Format("{0}\\Drawing Tools", Title)

      cmdGroup7 = iCmdMgr.CreateCommandGroup2(cmdGroupID7, subMenuTitle, "Colors", "", 7, ignorePrevious, cmdGroupErr)

      cmdGroup7.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypeDRAWING

       

      cmdGroup7.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup7.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup7.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

                 cmdGroup7.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdIndex16 As Integer = cmdGroup7.AddCommandItem2("Copy Drawing", 0, "Copy Drawing", "Copy Drawing", 49, "CopyDrawing", "", mainItemID15, menuToolbarOption)

      Dim cmdIndex17 As Integer = cmdGroup7.AddCommandItem2("Insert Flat View", 1, "Insert Flat View", "Insert Flat View", 18, "InsertFlatView", "", mainItemID16, menuToolbarOption)

      Dim cmdIndex20 As Integer = cmdGroup7.AddCommandItem2("Reload Sheet", 2, "Reload Sheet", "Reload Sheet", 20, "ReloadSheet", "", mainItemID19, menuToolbarOption)

      Dim cmdIndex21 As Integer = cmdGroup7.AddCommandItem2("Copy BOM", 3, "Copy BOM", "Copy BOM", 50, "CopyBOM", "", mainItemID20, menuToolbarOption)

       

      cmdGroup7.HasToolbar = True

      cmdGroup7.HasMenu = True

      cmdGroup7.Activate()

       

      ' Hose/Tube Drawing Sub Menu

      subMenuTitle = String.Format("{0}\\Hose/Tube Drawing", Title)

      cmdGroup8 = iCmdMgr.CreateCommandGroup2(cmdGroupID8, subMenuTitle, "Hose/Tube Drawing", "", 7, ignorePrevious, cmdGroupErr)

      cmdGroup8.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypeDRAWING

       

      cmdGroup8.LargeIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarLarge.bmp", thisAssembly)

      cmdGroup8.SmallIconList = iBmp.CreateFileFromResourceBitmap("VermeerTools.ToolbarSmall.bmp", thisAssembly)

      cmdGroup8.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconLarge.bmp", thisAssembly)

      cmdGroup8.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.MainIconSmall.bmp", thisAssembly)

       

      Dim cmdIndex18 As Integer = cmdGroup8.AddCommandItem2("Hose Drawing", -1, "Hose Drawing", "HoseDraing", 0, "HoseDrawing", "", mainItemID17, menuToolbarOption)

      Dim cmdIndex19 As Integer = cmdGroup8.AddCommandItem2("Tube Drawing", -1, "Tube Drawing", "Tube Drawing", 1, "TubeDrawing", "", mainItemID18, menuToolbarOption)

       

      cmdGroup8.HasToolbar = True

      cmdGroup8.HasMenu = True

      cmdGroup8.Activate()

       

      Dim flyGroupVMC As FlyoutGroup

      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.VMCMainIconLarge.bmp", thisAssembly)

      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.VMCMainIconSmall.bmp", thisAssembly)

       

      flyGroupVMC = iCmdMgr.CreateFlyoutGroup(flyoutGroupID1, "VMC", "VMC", "VMC", _

      cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, _

      cmdGroup.LargeIconList, "FlyoutCallbackVMC", "FlyoutEnable")

       

      flyGroupVMC.AddCommandItem("VMC", "VMC", 0, "VMC", "FlyoutEnableCommandItem1")

      flyGroupVMC.AddCommandItem("Prop Copy", "Prop Copy", 9, "PropCopy", "FlyoutEnableCommandItem1")

      flyGroupVMC.AddCommandItem("Revision Delete", "Revision Delete", 8, "RevisionDelete", "FlyoutEnableCommandItem1")

       

      flyGroupVMC.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

       

      Dim flyGroupColors As FlyoutGroup

      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.ColorsMainIconLarge.bmp", thisAssembly)

      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.ColorsMainIconSmall.bmp", thisAssembly)

       

      flyGroupColors = iCmdMgr.CreateFlyoutGroup(flyoutGroupID2, "Vermeer Colors", "Vermeer Colors", "Vermeer Colors", _

      cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, _

      cmdGroup.LargeIconList, "FlyoutCallbackColors", "FlyoutEnable")

       

      flyGroupColors.AddCommandItem("Random Color", "Random Color", 23, "RandomColor", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Vermeer Yellow", "Vermeer Yellow", 24, "VermeerYellow", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Vermeer Black", "Vermeer Black", 25, "VermeerBlack", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Vermeer Green", "Vermeer Green", 26, "VermeerGreen", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Vermeer White", "Vermeer White", 27, "VermeerWhite", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Vermeer Red", "Vermeer Red", 28, "VermeerRed", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Clear Zinc", "Clear Zinc", 47, "ClearZinc", "FlyoutEnableCommandItem1")

      flyGroupColors.AddCommandItem("Yellow Zinc", "Yellow Zinc", 48, "YellowZinc", "FlyoutEnableCommandItem1")

       

      flyGroupColors.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

       

      Dim flyGroupNotes As FlyoutGroup

      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.NotesMainIconLarge.bmp", thisAssembly)

      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.NotesMainIconSmall.bmp", thisAssembly)

       

      flyGroupNotes = iCmdMgr.CreateFlyoutGroup(flyoutGroupID3, "Common Notes", "Common Notes", "Common Notes", _

      cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, _

      cmdGroup.LargeIconList, "FlyoutCallbackNotes", "FlyoutEnable")

       

      flyGroupNotes.AddCommandItem("Common Notes", "Common Notes", 21, "CommonNotes", "FlyoutEnableCommandItem1")

      flyGroupNotes.AddCommandItem("English", "English Notes", 29, "EnglishNotes", "FlyoutEnableCommandItem1")

      flyGroupNotes.AddCommandItem("Dutch", "Dutch Notes", 30, "DutchNotes", "FlyoutEnableCommandItem1")

      flyGroupNotes.AddCommandItem("Chinese", "Chinese Notes", 31, "ChineseNotes", "FlyoutEnableCommandItem1")

       

      flyGroupNotes.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

       

      Dim flyGroupHoseDrawing As FlyoutGroup

      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.HoseDrawingMainIconLarge.bmp", thisAssembly)

      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.HoseDrawingMainIconSmall.bmp", thisAssembly)

       

      flyGroupHoseDrawing = iCmdMgr.CreateFlyoutGroup(flyoutGroupID4, "Hose Drawing", "Hose Drawing", "Hose Drawing", _

      cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, _

      cmdGroup.LargeIconList, "FlyoutCallbackHoseDrawing", "FlyoutEnable")

      flyGroupHoseDrawing.AddCommandItem("New Hose Drawing", "New Hose Drawing", 4, "HoseDrawing", "FlyoutEnableCommandItem1")

      flyGroupHoseDrawing.AddCommandItem("Edit Hose Drawing", "Edit Hose Drawing", 4, "EditHoseDrawing", "FlyoutEnableCommandItem1")

      flyGroupHoseDrawing.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

       

      Dim flyGroupTubeDrawing As FlyoutGroup

      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.TubeDrawingMainIconLarge.bmp", thisAssembly)

      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("VermeerTools.TubeDrawingMainIconSmall.bmp", thisAssembly)

       

      flyGroupTubeDrawing = iCmdMgr.CreateFlyoutGroup(flyoutGroupID5, "Tube Drawing", "Tube Drawing", "Tube Drawing", _

      cmdGroup.SmallMainIcon, cmdGroup.LargeMainIcon, cmdGroup.SmallIconList, _

      cmdGroup.LargeIconList, "FlyoutCallbackTubeDrawing", "FlyoutEnable")

      flyGroupTubeDrawing.AddCommandItem("New Tube Drawing", "New Tube Drawing", 5, "TubeDrawing", "FlyoutEnableCommandItem1")

      flyGroupTubeDrawing.AddCommandItem("Edit Tube Drawing", "Edit Tube Drawing", 5, "EditTubeDrawing", "FlyoutEnableCommandItem1")

      flyGroupTubeDrawing.FlyoutType = swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple

       

      ' Command Manager setup

       

      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(1) As Integer

      Dim TextType(1) As Integer

       

      cmdIDs(0) = flyGroupVMC.CmdID

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = flyGroupColors.CmdID

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox.AddCommands(cmdIDs, TextType)

       

      Dim cmdBox1 As CommandTabBox = cmdTab.AddCommandTabBox()

      ReDim cmdIDs(3)

      ReDim TextType(3)

       

      cmdIDs(0) = cmdGroup.CommandID(cmdIndex11)

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = cmdGroup.CommandID(cmdIndex12)

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(2) = cmdGroup.CommandID(cmdIndex13)

      TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox1.AddCommands(cmdIDs, TextType)

       

      cmdTab.AddSeparator(cmdBox1, cmdIDs(0))

       

      Dim cmdBox2 As CommandTabBox = cmdTab.AddCommandTabBox()

      ReDim cmdIDs(7)

      ReDim TextType(7)

       

      cmdIDs(0) = cmdGroup.CommandID(cmdIndex14)

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = cmdGroup.CommandID(cmdIndex15)

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(2) = cmdGroup.CommandID(cmdIndex16)

      TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(3) = flyGroupHoseDrawing.CmdID

      TextType(3) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(4) = flyGroupTubeDrawing.CmdID

      TextType(4) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(5) = cmdGroup.CommandID(cmdIndex20)

      TextType(5) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(6) = cmdGroup.CommandID(cmdIndex21)

      TextType(6) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox2.AddCommands(cmdIDs, TextType)

       

      cmdTab.AddSeparator(cmdBox2, cmdIDs(0))

       

      Dim cmdBox3 As CommandTabBox = cmdTab.AddCommandTabBox()

      ReDim cmdIDs(3)

      ReDim TextType(3)

       

      cmdIDs(0) = flyGroupNotes.CmdID

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = cmdGroup.CommandID(cmdIndex34)

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(2) = cmdGroup.CommandID(cmdIndex35)

      TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox3.AddCommands(cmdIDs, TextType)

       

      cmdTab.AddSeparator(cmdBox3, cmdIDs(0))

       

      Dim cmdBox4 As CommandTabBox = cmdTab.AddCommandTabBox()

      ReDim cmdIDs(3)

      ReDim TextType(3)

       

      cmdIDs(0) = cmdGroup.CommandID(cmdIndex25)

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = cmdGroup.CommandID(cmdIndex26)

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(2) = cmdGroup.CommandID(cmdIndex27)

      TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox4.AddCommands(cmdIDs, TextType)

       

      cmdTab.AddSeparator(cmdBox4, cmdIDs(0))

       

      Dim cmdBox5 As CommandTabBox = cmdTab.AddCommandTabBox()

      ReDim cmdIDs(2)

      ReDim TextType(2)

       

      cmdIDs(0) = cmdGroup.CommandID(cmdIndex29)

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = cmdGroup.CommandID(cmdIndex30)

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox5.AddCommands(cmdIDs, TextType)

       

      cmdTab.AddSeparator(cmdBox5, cmdIDs(0))

       

      Dim cmdBox6 As CommandTabBox = cmdTab.AddCommandTabBox()

      ReDim cmdIDs(3)

      ReDim TextType(3)

       

      cmdIDs(0) = cmdGroup.CommandID(cmdIndex32)

      TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(1) = cmdGroup.CommandID(cmdIndex33)

      TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      cmdIDs(2) = cmdGroup.CommandID(cmdindex46)

      TextType(2) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      bResult = cmdBox6.AddCommands(cmdIDs, TextType)

       

      cmdTab.AddSeparator(cmdBox6, cmdIDs(0))

       

      'Dim cmdBox7 As CommandTabBox = cmdTab.AddCommandTabBox()

      'ReDim cmdIDs(2)

      'ReDim TextType(2)

       

      'cmdIDs(0) = cmdGroup.CommandID(cmdIndex32)

      'TextType(0) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      'cmdIDs(1) = cmdGroup.CommandID(cmdIndex33)

      'TextType(1) = swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow

       

      'bResult = cmdBox7.AddCommands(cmdIDs, TextType)

       

      'cmdTab.AddSeparator(cmdBox7, cmdIDs(0))

       

      End If

      Next

       

      thisAssembly = Nothing

       

              Catch ex As Exception

       

              End Try

          End Sub

        • Re: Setting up toolbars and menus
          Andrew Johnson

          Hi Greg,

          Impressive collection of commands you have there!

           

          I'm in a similar situation where I want a more flexible system for creating Command menus and tabs, so I created a system that allows me to create the menus in a way that is easier to modify/maintain (in my opinion).

           

          It doesn't support flyout menus yet, mainly because I don't use them in my Add-In at this point, but maybe eventually.

           

          See below for a portion of your code converted to my system (in C#), and the results. As you can see, you basically construct the menu by creating items and submenus in the order you want them to display on screen. No need to store and recall commandIndex or commandID integer values, etc. It is taken care of for you. If you need to add another color between Vermeer White and Clear Zinc, just insert a colorsGroup.AddCommandItem call. Store the SwCommandItem return value and add it to the colorsTabBox below.

           

          You can choose how much or how little info you want to provide. For example, in many cases a Command Item title, hint, and tooltip can be the same. Just provide the title in the AddCommandItem method and hint/tooltip use title automatically. If you want to provide them explicitly, you can.

           

          If this looks useful to you, feel free to get ahold of me via private message.

           

          public void AddCommandMgr()
                  {
                      var thisAssembly = Assembly.GetAssembly(GetType());
                      if (iBmp == null) { iBmp = new BitmapHandler(); }
                      const string title = "Vermeer Tools";
                      const string toolTip = "Vermeer Tools for SolidWorks";
                      var docTypes = new List<int>
                      {
                          (int)swDocumentTypes_e.swDocASSEMBLY,
                          (int)swDocumentTypes_e.swDocDRAWING,
                          (int)swDocumentTypes_e.swDocPART
                      };
                      
                      var largeIconListPath = iBmp.CreateFileFromResourceBitmap("CommandManagerToolsTestAddIn.ToolbarLarge.bmp", thisAssembly);
                      var smallIconListPath = iBmp.CreateFileFromResourceBitmap("CommandManagerToolsTestAddIn.ToolbarSmall.bmp", thisAssembly);
                      var largeMainIconPath = iBmp.CreateFileFromResourceBitmap("CommandManagerToolsTestAddIn.MainIconLarge.bmp", thisAssembly);
                      var smallMainIconPath = iBmp.CreateFileFromResourceBitmap("CommandManagerToolsTestAddIn.MainIconSmall.bmp", thisAssembly);
          
          
                      CommandManagerBuilder commandManagerBuilder = new CommandManagerBuilder(SwApp, addinID);
          
          
                      #region Main Command Group
          
          
                      SwCommandGroup commandGroup = new SwCommandGroup(mainCmdGroupID, title, toolTip, toolTip)
                      {
                          LargeIconStripPath = largeIconListPath,
                          SmallIconStripPath = smallIconListPath,
                          LargeMainIconPath = largeMainIconPath,
                          SmallMainIconPath = smallMainIconPath
                      };
          
          
                      commandGroup.AddCommandItem("VMC - Custom Properties", "VMC", 0);
                      commandGroup.AddSeparator();
          
          
                      #region Custom Property Tools Sub Menu
          
          
                      var customPropertyToolsGroup = commandGroup.AddCommandGroup("Custom Property Tools");
                      var propCopyItem = customPropertyToolsGroup.AddCommandItem("Prop Copy", "PropCopy", 9);
                      var revisionDeleteItem = customPropertyToolsGroup.AddCommandItem("Revision Delete", "RevisionDelete", 8);
                      var revisionUpdaterItem = customPropertyToolsGroup.AddCommandItem("Revision Updater", "RevisionUpdater", 35);
          
          
                      #endregion
          
          
                      commandGroup.AddSeparator();
          
          
                      #region Colors Sub Menu
          
          
                      var colorsGroup = commandGroup.AddCommandGroup("Colors");
                      var randomColorItem = colorsGroup.AddCommandItem("Random Color", "RandomColor", 23);
                      var vermeerYellowItem = colorsGroup.AddCommandItem("Vermeer Yellow", "VermeerYellow", 24);
                      var vermeerBlackItem = colorsGroup.AddCommandItem("Vermeer Black", "VermeerBlack", 25);
                      var vermeerGreenItem = colorsGroup.AddCommandItem("Vermeer Green", "VermeerGreen", 26);
                      var vermeerWhiteItem = colorsGroup.AddCommandItem("Vermeer White", "VermeerWhite", 27);
                      var clearZincItem = colorsGroup.AddCommandItem("Clear Zinc", "ClearZinc", 47);
                      var yellowZincItem = colorsGroup.AddCommandItem("Yellow Zinc", "YellowZinc", 48);
          
          
                      #endregion
          
          
                      commandGroup.AddSeparator();
                      commandGroup.AddCommandItem("New Drawing", "NewDrawing", 17);
                      commandGroup.AddSeparator();
                      commandGroup.AddCommandItem("Common Notes", "CommonNotes", 21);
                      commandGroup.AddSeparator();
                      commandGroup.AddCommandItem("Increment UP", "IncrementUP", 32);
                      commandGroup.AddCommandItem("Increment DOWN", "IncrementDOWN", 33);
          
          
                      #endregion
          
          
                      commandManagerBuilder.BuildCommandGroup(commandGroup);
          
          
                      #region Command Manager Tab
          
          
                      SwCommandTab commandTab = new SwCommandTab(title, docTypes);
          
          
                      #region Custom Properties Box
          
          
                      var customPropertiesTabBox = commandTab.AddCommandTabBox();
                      customPropertiesTabBox.AddCommand(propCopyItem);
                      customPropertiesTabBox.AddCommand(revisionDeleteItem);
                      customPropertiesTabBox.AddCommand(revisionUpdaterItem);
          
          
                      #endregion
          
          
                      #region Custom Properties Box
          
          
                      var colorsTabBox = commandTab.AddCommandTabBox();
                      colorsTabBox.AddCommand(randomColorItem);
                      colorsTabBox.AddCommand(vermeerYellowItem);
                      colorsTabBox.AddCommand(vermeerBlackItem);
                      colorsTabBox.AddCommand(vermeerGreenItem);
                      colorsTabBox.AddCommand(vermeerWhiteItem);
                      colorsTabBox.AddCommand(clearZincItem);
                      colorsTabBox.AddCommand(yellowZincItem);
          
          
                      #endregion
          
          
                      #endregion
          
          
                      commandManagerBuilder.BuildCommandTab(commandTab, commandGroup);
                  }
          

           

          ToolsMenuTest.png

           

          CommandTabTest.png