Command.Enabled

Description

Returns or sets a Boolean indicating whether the command is enabled (true) or not (false) This flag only affects the user interface; it does not block the command from being executed from a script. This property is often used in conjunction with the Menu API. You must call Command.Update to make sure the command state is updated.

Examples

JScript Example

/*
        Example showing how custom commands
        can be defined and added to custom menus inside a
        self installed plug-in.
        Adds two entries to the "Window" menu 
        The first item is greyed out
        The second item allows you to enable or disable the first item. 
*/
function XSILoadPlugin( in_reg )
{
        // Called on startup of Softimage to defined
        // what is contained in the script.  (We could potentially
        // implement many PluginItems in the same script)
        in_reg.Author = "Softimage SDK Team" ;
        in_reg.Name = "SDK Example - Enabled Command" ;
        in_reg.Major = 1 ;
        in_reg.Minor = 1 ;
        in_reg.RegisterMenu( siMenuMainWindowID, "DemoMenu", false ) ;
        in_reg.RegisterCommand( "DemoDisabled", "DemoDisabled" );
        in_reg.RegisterCommand( "EnableDemoDisabled", "EnableDemoDisabled" );
        return true ;
}
function DemoMenu_Init( in_oCtxt )
{
        var menu = in_oCtxt.Source
        menu.Name = "&Custom Deform" ;
        menu.AddCommandItem( "&Demo Disabled", "DemoDisabled" ) ;
        menu.AddCommandItem( "&Toggle Demo Disabled", "EnableDemoDisabled" ) ;
}
function DemoDisabled_Init(in_oCtxt)
{
        var cmd = in_oCtxt.Source ;
        cmd.Enabled = false ;
        cmd.ReturnValue = false ;
}
function DemoDisabled_Execute()
{
        LogMessage( "Thanks for enabling me finally" ) ;
}
function EnableDemoDisabled_Init(in_oCtxt)
{
        var cmd = in_oCtxt.Source ;
        cmd.Enabled = true ;
        cmd.ReturnValue = false ;
}
function EnableDemoDisabled_Execute()
{
        var cmd = Application.Commands( "DemoDisabled" ) ;
        // Toggle the enabled bit
        if ( cmd.Enabled )
                cmd.Enabled = false ;
        else
                cmd.Enabled = true ;
        // Update the definition
        cmd.Update() ;
}