Hosting SOLIDWORKS commands in menu, toolbar and context menu using xCAD
Defined commands can be hosted in different locations of SOLIDWORKS commands area: command group, which includes menu, toolbar and command tab box (ribbon) as well as in the context menu
Command Group
In order to add command group it is required to call the AddCommandGroup method and pass the enumeration type as a generic parameter.
It is required to provide the void handler function with a parameter of enumerator which will be called by framework when command is clicked.
this.CommandManager.AddCommandGroup<CommandsA_e>().CommandClick += OnCommandsAButtonClick; this.CommandManager.AddCommandGroup<CommandsB_e>().CommandClick += OnCommandsBButtonClick; this.CommandManager.AddCommandGroup<CommandsC_e>().CommandClick += OnCommandsCButtonClick;
private void OnCommandsAButtonClick(CommandsA_e cmd) { //handle the button click } private void OnCommandsBButtonClick(CommandsB_e cmd) { //handle the button click } private void OnCommandsCButtonClick(CommandsC_e cmd) { //handle the button click }
Menu
By default command will be added to menu and toolbar. This behavior can be changed by assigning the hasMenu boolean parameter of the CommandItemInfoAttribute attribute.
Toolbar
By default command will be added to menu and toolbar. This behavior can be changed by assigning the hasToolbar boolean parameter of the CommandItemInfoAttribute attribute.
Command Tab Box
Command item can be added to tab box by setting the showInCmdTabBox parameter of CommandItemInfoAttribute to true for the specific command defined in the enumeration.
textStyle parameter allows to specify the alignment of the hint text relative to the icon.
- Icon only (without text) (NoText)
- Text below icon (TextBelow)
- Text to the right to icon, aligned horizontally (TextHorizontal)
using Xarial.XCad.UI.Commands.Attributes; using Xarial.XCad.UI.Commands.Enums; public enum CommandsC_e { [CommandItemInfo(true, true, WorkspaceTypes_e.Assembly, true, RibbonTabTextDisplay_e.NoText)] CommandC1, [CommandItemInfo(true, true, WorkspaceTypes_e.AllDocuments, true, RibbonTabTextDisplay_e.TextBelow)] CommandC2, [CommandItemInfo(true, true, WorkspaceTypes_e.AllDocuments, true, RibbonTabTextDisplay_e.TextHorizontal)] CommandC3, }
Context Menu
In order to add context menu it is required to call the AddContextMenu method and pass the enumeration as a template parameter.
It is required to provide the void handler function with a parameter of enumeration which will be called by framework when command is clicked.
It is optionally required to specify the selection type of where this menu should be displayed.
this.CommandManager.AddContextMenu<CommandsD_e>().CommandClick += OnCommandsDContextMenuClick; this.CommandManager.AddContextMenu<CommandsE_e>().CommandClick+= OnCommandsEContextMenuClick;
private void OnCommandsDContextMenuClick(CommandsD_e cmd) { //handle the context menu click } private void OnCommandsEContextMenuClick(CommandsE_e cmd) { //handle the context menu click }