XCAD.NET
XCAD.NET
Framework for .NET (C# and VB.NET) to create modern application for CAD systems (SOLIDWORKS)
Get technical support Access source code Explore code and application examples

Custom enable command state for SOLIDWORKS commands


There are 4 command states supported by SOLIDWORKS:

  1. Deselected and enabled. This is default option when button can be clicked
  2. Deselected and disabled. This option is used when the command is not supported in certain framework. For example mate command will be disabled in parts and drawings as it is only supported in the assemblies.
  3. Selected and disabled. This represents the disabled checked button
  4. Selected and enabled. This represents checked button

Supported command states
Supported command states

xCAD.NET framework will assign the appropriate state (enabled or disabled) for the commands based on their supported workspaces if defined in the CommandItemInfoAttribute. However user can alter the state to provide more advanced management (for example it might be required to enable command if certain object is selected or if any bodies or components are present in the model). To do this it is required to specify to subscribe to IXCommandGroup::CommandStateResolve event. IXCommandGroup is created as the result of calling AddCommandGroup or AddContextMenu methods.

The value of state will be preassigned based on the workspace and can be changed by the user within the method.

This method allows to implement the toggle button in toolbar and menu. To set the checked state use the Checked.

public enum Commands_e
{
    Command1,
    Command2
}

public override void OnConnect()
{
    this.CommandManager.AddCommandGroup<Commands_e>().CommandStateResolve += OnButtonEnable;
}

private void OnButtonEnable(Commands_e cmd, CommandState state)
{
    switch (cmd)
    {
        case Commands_e.Command1:
        case Commands_e.Command2:
            //TODO: implement logic to identify the state of the button
            state.Checked = false;
            state.Enabled = false;
            break;
    }
}

Refer Toggle Command Example for the demonstration of how to achieve check box effect for toolbar button in SOLIDWORKS using the command states.


Powered by Docify