Adding sub-menus and spacers to SOLIDWORKS command manager using SwEx.AddIn

Edit ArticleEdit Article

Adding spacer

Spacer can be added between the commands by decorating the command using the CommandSpacerAttribute. Spacer will be added before this command.

public enum Commands_e
{
    Command1,

    [CommandSpacer]
    Command2
}

If command tab tab boxes are created for this command group (i.e. showInCmdTabBox parameter is set to true in the CommandItemInfoAttribute), spacer is not reflected in the corresponding command tab box.

Adding sub-menus

Sub-menus for the command groups can be defined by calling the corresponding overload of the CommandGroupInfoAttribute attribute and specifying the type of the parent menu group

[CommandGroupInfo(typeof(Commands_e))]
public enum SubCommands_e
{
    SubCommand1,
    SubCommand2
}

Sub menus are rendered in separate tab boxes in the command tab.

Example

[Title("AddInEx Commands")]
public enum Commands_e
{
    Command1,

    [CommandSpacer]
    Command2
}

[Title("Sub Menu Commands")]
[CommandGroupInfo(typeof(Commands_e))]
public enum SubCommands_e
{
    SubCommand1,
    SubCommand2
}

public override bool OnConnect()
{
    AddCommandGroup<Commands_e>(OnButtonClick);
    AddCommandGroup<SubCommands_e>(OnButtonClick);
    return true;
}

private void OnButtonClick(Commands_e cmd)
{
}

private void OnButtonClick(SubCommands_e cmd)
{
}

The above commands configuration would result in the following menu and command tab boxes created:

Sub-menus and spacer
Sub-menus and spacer

  • Command1 and Command2 are commands of the top level menu defined in Commands_e enumeration
  • Spacer is added between Command1 and Command2
  • SubCommand1 and SubCommand2 are commands of SubCommands_e enumeration which is a sub menu of Commands_e enumeration

Command tab boxes
Command tab boxes

  • All commands (including sub menu commands) are added on the same command tab
  • Command1 and Command2 are placed in a separate command tab boxes of SubCommand1 and SubCommand2
  • Spacer between Command1 and Command2 is ignored in the commands tab

Product of Xarial Product of Xarial