MenuItem.Enabled
 
 
 

MenuItem.Enabled

Introduced

v5.0

Description

Sets or returns a Boolean indicating whether the menu item is enabled (true) or not. Menu objects can also be enabled or disabled which means all menu items defined in a menu are affected. This property is typically used for updating a menu item based on a specific context.

C# Syntax

// get accessor
Boolean rtn = MenuItem.Enabled;
// set accessor
MenuItem.Enabled = Boolean;

Examples

JScript Example

/*
        This example showing how to enable/disable custom menus defined in 
        a self-installing plug-in.
        Adds a menu in the top menu bar with 3 menu items.
        The first item is a greyed out menu item
        The second item is greyed out submenu item
        The third item allows you to enable or disable the first and second item. 
*/
function XSILoadPlugin( in_reg )
{
        in_reg.Author = "Softimage SDK team";
        in_reg.Name = "DemoMenuPlugin";
        in_reg.Major = 1;
        in_reg.Minor = 0;
        var bSubmenu = true; // value ignored for top level menus
        var bDynamic = true;
        in_reg.RegisterMenu(siMenuMainTopLevelID,"Demo Menu",bSubmenu,bDynamic);
        return true;
}
function DemoMenu_Init( ctxt )
{       
        if ( ctxt.UserData == undefined )
        {
                // disable demo menu items if the user data is not set yet
                ctxt.UserData = false;
        }
        var menu = ctxt.Source;
        var bEnabled = ctxt.UserData;
        var strTitle = "Demo menu item is enabled";
        var strSubmenuTitle = "Demo sub menu is enabled";
        if ( bEnabled == false )
        {
                strTitle = "Demo menu item is disabled";
                strSubmenuTitle = "Demo sub menu is disabled";
        }
        var menuitem = menu.AddCallbackItem(strTitle,"OnDemoMenuItem");
        menuitem.Enabled = bEnabled;
        var submenu = menu.AddItem( strSubmenuTitle, siMenuItemSubmenu );
        submenu.AddCallbackItem(strTitle,"OnDemoMenuItem");
        submenu.Enabled = bEnabled;     
        menu.AddCallbackItem("Toggle Demo menu","OnToggleDemoMenuItem");
        return true;
}
function OnDemoMenuItem( in_ctxt )
{
        LogMessage( "OnDemoMenuItem" );
}
function OnToggleDemoMenuItem( in_ctxt )
{       
        // toggles the enabled flag
        if ( in_ctxt.UserData == true )
        {
                in_ctxt.UserData = false;
        }
        else
        {
                in_ctxt.UserData = true;
        }
}