XCAD.NET
XCAD.NET
Framework for .NET (C# and VB.NET) to create modern application for CAD systems (SOLIDWORKS, SOLIDWORKS Document Manager, Autodesk Inventor, etc.)
Get technical support Connect to xCAD community on Discord server Explore code and application examples xCAD.NET Templates for Visual Studio and VS Code Access source code

Adding sub-menus and spacers to SOLIDWORKS command manager using xCAD


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 CommandGroupParent attribute and specifying the type of the parent menu group or the user id

[CommandGroupParent(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")]
[CommandGroupParent(typeof(Commands_e))]
public enum SubCommands_e
{
    SubCommand1,
    SubCommand2
}

public override void OnConnect()
{
    this.CommandManager.AddCommandGroup<Commands_e>().CommandClick += OnButtonClick;
    this.CommandManager.AddCommandGroup<SubCommands_e>().CommandClick += OnButtonClick;
}

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

Powered by Docify