Looking for VB.NET Example for creating a CommandGroup with submenus

Hi there,

I've been looking at tons of stuff and obviously I'm not looking at the right stuff.

I'm trying to create a command group with submenus. Nice examples are available to do just that.

Yet, I can't figure out how to make the top menu item and its submenu items to be also accessible in both the toolbar and the command tab.

If anyone has a VB.NET code example that does all that, please post it. I wanna know what I do wrong.

Thanks,

Antoine

SolidworksApi macros
Answers 12
JC
JC 2010-05-11 Best Answer

Dim cmdGroup As SldWorks.ICommandGroup

TOPMenu= iCmdMgr.CreateCommandGroup(1, "TOPMenu", "", "", -1)

TOPMenu.AddCommandItem

SubMenu= iCmdMgr.CreateCommandGroup(2, TOPMenu\\SubMenu", "Code Component as a (B)uy ,(I)con Assists, or (M)ake", "Coding", -1)

SubMenu.AddCommandItem

the double \\ will create a submenu

SF
SF 2010-05-11

There's got to be something missing here...

I know about de "\\" to create submenus. And I'm doing that fine.

But it won't make that submenu turn into sub command items in the command group toolbar and command tab.

Just as the "Insert Component" command in the SW assembly toolbar.

Antoine

JC
JC 2010-05-11

cmdGroup.HasMenu = True
     cmdGroup.HasToolbar = True

SF
SF 2010-05-11

Already got that...

Looks like I need to post some code...

     cmdTopGroup = _iCmdMgr.CreateCommandGroup(cmdTopGroupUserID, "TopGroupTitle", "TopGroupToolTip", "TopGroupHint", 6)

     If Not cmdTopGroup Is Nothing Then

            cmdTopGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("ToolbarLarge.bmp", thisAssembly)
            cmdTopGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("ToolbarSmall.bmp", thisAssembly)
            cmdTopGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("MainIconLarge.bmp", thisAssembly)
            cmdTopGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("MainIconSmall.bmp", thisAssembly)

            cmdTopGroup.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypeNONE + _
                                                                                 swDocTemplateTypes_e.swDocTemplateTypePART + _
                                                                                 swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY

            cmdItem1ID = cmdTopGroup.AddCommandItem2("Item1Name", -1, "Item1Hint", "Item1ToolTip", 1, "Item1CallBack", "EnableItem1", cmdItem1UserID, _
                                           swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdSpacer1ID = cmdTopGroup.AddSpacer2(-1, swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdSpacer2ID = cmdTopGroup.AddSpacer2(-1, swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdItem2ID = cmdTopGroup.AddCommandItem2("Item2Name", -1, "Item2Hint", "Item2ToolTip", 1, "Item2CallBack", "EnableItem2", cmdItem2UserID, _
                                           swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdSpacer3ID = cmdTopGroup.AddSpacer2(-1, swCommandItemType_e.swMenuItem)

            cmdItem3ID = cmdTopGroup.AddCommandItem2("Item3Name", -1, "Item3Hint", "Item3ToolTip", 1, "Item3CallBack", "EnableItem3", cmdItem3UserID, _
                                           swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdItem4ID = cmdTopGroup.AddCommandItem2("Item4Name", -1, "Item4Hint", "Item4ToolTip", 1, "Item4CallBack", "EnableItem4", cmdItem4UserID, _
                                           swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdTopGroup.HasToolbar = True
            cmdTopGroup.HasMenu = True

            cmdTopGroup.MenuPosition(swDocTemplateTypes_e.swDocTemplateTypeNONE) = 3
            cmdTopGroup.MenuPosition(swDocTemplateTypes_e.swDocTemplateTypePART) = 6
            cmdTopGroup.MenuPosition(swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY) = 6

            cmdTopGroup.Activate()

        End If

        cmdSubGroup = _iCmdMgr.CreateCommandGroup(cmdSubGroupUserID, "TopGroupTitle\\SubGroupTitle", "", "", 2)

        If Not cmdOpenDocGroup Is Nothing Then

           

            cmdSubGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("ToolbarLarge.bmp", thisAssembly)
            cmdSubGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("ToolbarSmall.bmp", thisAssembly)
            cmdSubGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("MainIconLarge.bmp", thisAssembly)
            cmdSubGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("MainIconSmall.bmp", thisAssembly)

            cmdSubGroup.ShowInDocumentType = swDocTemplateTypes_e.swDocTemplateTypeNONE + _
                                                                                 swDocTemplateTypes_e.swDocTemplateTypePART + _
                                                                                 swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY

            cmdSubItem1ID = cmdSubGroup.AddCommandItem2("SubItem1Name", -1, "SubItem1Hint", "SubItem1ToolTip", 1, "SubItem1CallBack", _

                                                                                                          "EnableSubItem1", cmdSubItem1UserID, _

                                                                                                          swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

            cmdSubItem2ID = cmdSubGroup.AddCommandItem2("SubItem2Name", -1, "SubItem2Hint", "SubItem2ToolTip", 1, "SubItem2CallBack", _

                                                                                                          "EnableSubItem2", cmdSubItem2UserID, _

                                                                                                          swCommandItemType_e.swMenuItem + swCommandItemType_e.swToolbarItem)

           

            cmdSubGroup.HasToolbar = True
            cmdSubGroup.HasMenu = True
            cmdSubGroup.Activate()

        End If

That way, the menu is perfectly fine. But as for the toolbar and command tab, they are separated. And I don't want that.

Antoine

PS: Jacob, have you a working example of what I'm asking, or you are just throwing me code bits to try and see ? Because I asked for the former... I covered the later.

JC
JC 2010-05-11

I do have software that i do this in

I also get mulit-toolbar for each submenu

one thing you can do is have one command group for menubar with summenus

and  on command group for the toolbar  with on sub menus

I have not tried this but then why are the the option that I last posted

SF
SF 2010-05-11

Is your software coded like mine ? Because if it is, what's going wrong on my side ?

JC
JC 2010-05-11

my code is almose like your I get the same thing where the toolbar are only the one muenu and not the submenu

SF
SF 2010-05-11

Ok, that means that the CommandGroup object doesn't allow for submenus in toolbars.

Meaning, I have to look elsewhere... Unless someone else has an idea ?

SF
SF 2010-05-12

Are you looking for something like that?

________________________________________________________________

SolidWorks API Tips & Tricks: http://amcbridge.com/?q=SolidWorksApiBlog
comment imagecomment image
SF
SF 2010-05-12

Yes, that's what I'm looking for in the Command Tab. But I also want that result in my toolbar.

Look for the "Insert component" flyout tool in the Assembly toolbar and Command Tab : that's the behaviour I want for my commands.

Right now, I just can't get the low-level command groups anywhere on a toolbar or a command tab. All I get is a separate toolbar in addition to the top command group's toolbar.

I'm trying to add the low level toolbar to my Command Tab using its toolbarID, but it doesn't work.

SF
SF 2010-05-12

More on the matter...

If I do it manually by customizing my main toolbar and command tab in SW, I can get the low level toolbar as a flyout toolbar in the top one, but I can't get it done in the command tab.

Could it be an isuue with my icons ? They seem to lose there transparency when instanciated as flyout tool commands...

SF
SF 2010-05-12

Alright! I found some answers!

First, about not being able to add a toolbarID to a CommandTab, here is the faulty code line:

cmdSubGroup = _iCmdMgr.CreateCommandGroup(cmdSubGroupUserID, "TopGroupTitle\\SubGroupTitle", "", "", 2)

The command group is incomplete as it doesn't have a ToolTip string and a Hint String. The text shown on a CommandTab is the ToolTip string, so if there's none, it won't show up. I completed the parameters with two string and I now have the low-level toolbar on my CommandTab.

Second, about that transparency issue : it was a bitmap issue. They weren't 256-colors bitmap. Doh...

So far, so good. I still can't get the low-level toolbar in the top-level one, just as Jacob experienced with his software. Also, I would like the low-level toolbar to be strictly a flyout toolbar (have to be a sub toolbar).