//-------------------------------------------------------------------
// This example defines & runs a custom command examples
//
//
// README: Copy and paste the example into the script editor
// and run (F5).
//
// The command will be listed in the customize toolbar dialog in
// the 'Custom Commands' group.
//-------------------------------------------------------------------
function ExCreateCommandDemo()
{
Application.RemoveCommand("XYZ");
var cmd = Application.CreateCommand("XYZ");
cmd.Description = "XYZ custom command.";
cmd.ScriptingName = "XYZ";
cmd.Handler = "OnXYZCommand";
cmd.FileName = filename;
cmd.Language = "JScript";
cmd.Arguments.Add( "argument0" );
Application.AddCommand( cmd );
// call command
XYZ( "this is a string argument" );
}
// This sample defines the XYZ command's function handler"
function OnXYZCommand( in_arg )
{
LogMessage( "Executing XYZ command with the argument: " + in_arg );
}
//--------------------------------------------------------------------
// Code to bootstrap example into system
//--------------------------------------------------------------------
function ExampleSourceCode()
{
return "//XSISDK Doc Example\n" +
OnXYZCommand.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 = "ExXSIApplicationCreateCommand";
var ex_subfolder = "Scripts";
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,
"Data",
ex_subfolder,
ex_name+ex_langsuffix );
if (!fso.FileExists(filename))
{
var f = fso.CreateTextFile ( filename );
f.write( ExampleSourceCode() );
f.close();
}
// run demo
ExCreateCommandDemo();
} |