Hide Table of Contents

Create Submenus in the CommandManager Example (C#)

This example shows how to create submenus in the CommandManager framework by creating individual CommandGroups for each submenu in your tree. Create a C# addin using the SOLIDWORKS VSTA C# addin template. Set up CommandManager CommandGroups in SwAddin.ConnectToSW():

 

public bool ConnectToSW(SldWorks ThisSW, int Cookie)

{

            iApp = ThisSW;

            iCookie = Cookie;

 

            iApp.SetAddinCallbackInfo2(0, this, iCookie);

 

            iCommand = iApp.GetCommandManager(iCookie);

 

            SldWorks.CommandGroup commandGroup = null;

            string title = "CommandGroup1";

            string toolTip = "Command group 1 tip";

            string hint = "Command group 1 hint";

            int position = 6;

            commandGroup = iCommand.CreateCommandGroup(CommandGroupID1, title, toolTip, hint, position);

            if (commandGroup != null)

            {

                   BitmapHandler bitmapHandler = new BitmapHandler();

                   commandGroup.LargeIconList = bitmapHandler.CreateFileFromResource("CommandManager.LargeIconList.bmp");

                   commandGroup.LargeMainIcon = bitmapHandler.CreateFileFromResource("CommandManager.LargeMainIcon.bmp");

                   commandGroup.SmallIconList = bitmapHandler.CreateFileFromResource("CommandManager.SmallIconList.bmp");

                   commandGroup.SmallMainIcon = bitmapHandler.CreateFileFromResource("CommandManager.SmallMainIcon.bmp");

                   commandGroup.ShowInDocumentType = (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypeNONE;// |

//                            (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypePART |

//                            (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY |

//                            (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypeDRAWING;

 

                   commandGroup.AddCommandItem2("Command1", -1, "Command1 hint", "Command1 tool tip", 0, "OnCommand1", "OnMenuUpdate", 0, 1);

                   commandGroup.AddCommandItem2("Command2", -1, "Command2 hint", "Command2 tool tip", 1, "OnCommand2", "OnMenuUpdate", 0, 1);

 

                   commandGroup.HasMenu = true;

                   commandGroup.HasToolbar = true;

 

                   commandGroup.Activate();

            }

 

            commandGroup = null;

            title = "CommandGroup1\\CommandSubGroup1";

            toolTip = "Command sub group 1 tip";

            hint = "Command sub group 1 hint";

            position = -1;

            commandGroup = iCommand.CreateCommandGroup(CommandGroupID2, title, toolTip, hint, position);

            if (commandGroup != null)

            {

                 BitmapHandler bitmapHandler = new BitmapHandler();

                 commandGroup.LargeIconList = bitmapHandler.CreateFileFromResource("CommandManager.LargeIconList.bmp");

                 commandGroup.LargeMainIcon = bitmapHandler.CreateFileFromResource("CommandManager.LargeMainIcon.bmp");

                 commandGroup.SmallIconList = bitmapHandler.CreateFileFromResource("CommandManager.SmallIconList.bmp");

                 commandGroup.SmallMainIcon = bitmapHandler.CreateFileFromResource("CommandManager.SmallMainIcon.bmp");

                 commandGroup.ShowInDocumentType = (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypeNONE;// |

//                            (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypePART |

//                            (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypeASSEMBLY |

//                            (int)SwConst.swDocTemplateTypes_e.swDocTemplateTypeDRAWING;

 

                 commandGroup.AddCommandItem2("SubCommand1", -1, "Command1 hint", "Command1 tool tip", 0, "OnCommand1", "OnMenuUpdate", 0, 1);

                 commandGroup.AddCommandItem2("SubCommand2", -1, "Command2 hint", "Command2 tool tip", 1, "OnCommand2", "OnMenuUpdate", 0, 1);

 

                 commandGroup.HasMenu = true;

                 commandGroup.HasToolbar = true;

 

                 commandGroup.Activate();

           }

 

           return true;

 

}

 



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Create Submenus in the CommandManager Example (C#)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:




x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2018 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.