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

SwEx 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 the enable method handler as the last parameter of AddCommandGroup or AddContextMenu methods.

The method is defined as EnableMethodDelegate delegate and provides the command id as first parameter and state passed by reference as second parameter.

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


AddCommandGroup(Of Commands_e)(AddressOf OnCommand, AddressOf OnEnableCommand)

Private Sub OnEnableCommand(ByVal cmd As Commands_e, ByRef state As CommandItemEnableState_e)
    'set the value of state parameter based on the custom logic
End Sub


AddCommandGroup<Commands_e>(OnCommand, OnEnableCommand);

private void OnEnableCommand(Commands_e cmd, ref CommandItemEnableState_e state)
    //set the value of state parameter based on the custom logic