PluginRegistrar.RegisterMenu.1.js Example
Applies To
PluginRegistrar.RegisterMenu method
Description
This example demonstrates how to use the PluginRegistrar.RegisterMenu method.
Code
/*-------------------------------------------------------------------
This example shows how to register and implement a custom menu
plug-in
README: Copy and paste the example into the script editor
and run (F5).
The menu will install itself into the application's Window menu
-------------------------------------------------------------------*/
function XSILoadPlugin( in_reg )
{
in_reg.Author = "Softimage Co.";
in_reg.Name = "PluginRegistrar.RegisterMenu Example";
// register the menu item
in_reg.RegisterMenu( siMenuMainWindowID, "Window_Menu", false );
// "Sample menu has been installed in the Window menu"
return true;
}
function Window_Menu_Init( in_ctxt )
{
var oMenu = in_ctxt.source;
oMenu.AddCallbackItem( "Sample", "OnWindowMenu");
}
function OnWindowMenu( in_ctxt )
{
var oMenuItem = in_ctxt.source;
Application.LogMessage("OnWindowMenu: " + oMenuItem .name );
}
//--------------------------------------------------------------------
// Code to bootstrap example into system
//--------------------------------------------------------------------
function ExampleSourceCode()
{
return "// XSISDK Doc Example\n" +
Window_Menu_Init.toString() + "\n" +
OnWindowMenu.toString() + "\n" +
XSILoadPlugin.toString();
}
// if we are running from script editor save code to
// examples addon folder in the user's directory.
if (GetUserPref("ScriptingSessionActive"))
{
var ex_name = "ExPluginRegistrarRegisterMenu";
var ex_subfolder = "Plugins";
var ex_folder = "XSISDKDocExamples";
var ex_langsuffix = ".js";
CreateAddonDirectories( InstallationPath(siUserPath), ex_folder );
var fso = XSIFactory.CreateActiveXObject("Scripting.FileSystemObject");
var filename = XSIUtils.BuildPath(
InstallationPath(siUserAddonPath),
ex_folder,
"Application",
ex_subfolder,
ex_name+ex_langsuffix );
if (!fso.FileExists(filename))
{
var f = fso.CreateTextFile ( filename );
f.write( ExampleSourceCode() );
f.close();
Application.LoadPlugin(filename);
}
}Keywords
PluginRegistrar RegisterMenu
Autodesk Softimage 2011