Init (Menu)
 
 
 

Init (Menu)


Description

For dynamic menus, this callback is fired every time the menu is accessed. For static menus, this callback is fired the first time the menu is accessed after the plug-in is loaded.

This is where you add items and commands to a menu.


Applies To

Standard and Contextual Menus


Syntax

public class <menu_name>
{
        public bool Init( Context in_context )
        {
                ...
        }
}
CStatus <menu_name>_Init( CRef& in_context )
{ 
        ... 
}
function <menu_name>_Init( in_context )
{ 
        ... 
}
def <menu_name>_Init( in_context ):
        ...
Function <menu_name>_Init( in_context )
        ...
End Function
sub <menu_name>_Init 
{ 
        my $in_context = shift; 
}

<menu_name> is the name specified in the call to PluginRegistrar.RegisterMenu, with any spaces converted to underscores.


Parameters

Parameter Language Type Description
in_context Scripting and C# Context Context.Source returns the Menu.
C++ CRef& A reference to the Context object. Context::GetSource returns the Menu.

Examples

// JScript code generated by the Command Wizard
// Shows the Init callbacks for a command and for a menu
function XSILoadPlugin( in_reg )
{
 in_reg.Author = "sblair";
 in_reg.Name = "MyCommandPlugin";
 in_reg.Email = "";
 in_reg.URL = "";
 in_reg.Major = 1;
 in_reg.Minor = 0;

 in_reg.RegisterCommand("MyCommand","MyCommand");
 in_reg.RegisterMenu(siMenuTbGetPropertyID,"MyCommand_Menu",false,false);
 //RegistrationInsertionPoint - do not remove this line

 return true;
}

function XSIUnloadPlugin( in_reg )
{
 strPluginName = in_reg.Name;
 Application.LogMessage(strPluginName + " has been unloaded.");
 return true;
}

function MyCommand_Init( ctxt )
{
 var oCmd;
 oCmd = ctxt.Source;
 oCmd.Description = "";
 oCmd.ReturnValue = true;

 var oArgs;
 oArgs = oCmd.Arguments;
 oArgs.Add("Arg0",siArgumentInput);
 return true;
}

function MyCommand_Execute( Arg0 )
{

 Application.LogMessage("MyCommand_Execute called");
 // 
 // TODO: Put your command implementation here.
 // 
 return true;
}

function MyCommand_Menu_Init( ctxt )
{
 var oMenu;
 oMenu = ctxt.Source;
 oMenu.AddCommandItem("Run My Command","MyCommand");
 return true;
}
// C++ code generated by the Command Wizard
// Shows the Init callbacks for a command and a menu
#include <xsi_application.h>
#include <xsi_context.h>
#include <xsi_pluginregistrar.h>
#include <xsi_status.h>
#include <xsi_argument.h>
#include <xsi_command.h>
#include <xsi_menu.h>
using namespace XSI; 

SICALLBACK XSILoadPlugin( PluginRegistrar& in_reg )
{
 in_reg.PutAuthor(L"sblair");
 in_reg.PutName(L"My_CppCommandPlugin");
 in_reg.PutEmail(L"");
 in_reg.PutURL(L"");
 in_reg.PutVersion(1,0);
 in_reg.RegisterCommand(L"My_CppCommand",L"My_CppCommand1");
 in_reg.RegisterMenu(siMenuTbGetPropertyID,L"My_CppCommand_Menu",false,false);
 //RegistrationInsertionPoint - do not remove this line

 return CStatus::OK;
}

SICALLBACK XSIUnloadPlugin( const PluginRegistrar& in_reg )
{
 CString strPluginName = in_reg.GetName();
 Application().LogMessage(strPluginName + L" has been unloaded.");
 return CStatus::OK;
}

SICALLBACK My_CppCommand_Init( CRef& in_ctxt )
{
 Context ctxt( in_ctxt );
 Command oCmd;
 oCmd = ctxt.GetSource();
 oCmd.PutDescription(L"");
 oCmd.EnableReturnValue(true);

 ArgumentArray oArgs;
 oArgs = oCmd.GetArguments();
 oArgs.Add(L"Arg0");
 return CStatus::OK;
}

SICALLBACK My_CppCommand_Execute( CRef& in_ctxt )
{
 Context ctxt( in_ctxt );
 CValueArray args = ctxt.GetAttribute(L"Arguments");
 CValue Arg0 = args[0];

 Application().LogMessage(L"My_CppCommand_Execute called");
 // 
 // TODO: Put your command implementation here.
 // 
 // Return a value by setting this attribute:
 ctxt.PutAttribute( L"ReturnValue", true );

 // Return CStatus::Fail if you want to raise a script error
 return CStatus::OK;
}

SICALLBACK My_CppCommand_Menu_Init( CRef& in_ctxt )
{
 Context ctxt( in_ctxt );
 Menu oMenu;
 oMenu = ctxt.GetSource();
 MenuItem oNewItem;
 oMenu.AddCommandItem(L"My_CppCommand",L"My_CppCommand",oNewItem);
 return CStatus::OK;
}

See Also