Command.5.js Example

Applies To

Command object

Description

This example demonstrates how to use the Command object.

Code

/* --------------------------------------------------------------
	Hello World example, based on v1.5 workflow for defining a command
	This JScript example creates and registers a custom
	command and then demonstrates how you can find it in
	the Softimage command collection using the Builtin property.
----------------------------------------------------------- */
// Start off with a clean slate
Application.RemoveCommand("Howdy");
// Get the factory (installation) path and use it to build the filename & path
var sFileName = InstallationPath( siUserPath ) + "\\Data\\Scripts\\HelloWorld.js";
// Create a standard hello world script file
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var fHWFile = fso.CreateTextFile( sFileName  );
fHWFile.WriteLine( "function SayHi()" );
fHWFile.WriteLine( "{" );
fHWFile.WriteLine( "\tApplication.LogMessage( \"Hello, World!\" );" );
fHWFile.WriteLine( "}" );
fHWFile.Close();
// Add it to the command map in Softimage
var oCmd = Application.CreateCommand( "Howdy", siExportCategory );
oCmd.Description = "Display the traditional greeting";
oCmd.ScriptingName = "Howdy";
oCmd.Handler = "SayHi";
oCmd.FileName = sFileName;
oCmd.Language = "JScript";
Application.AddCommand( oCmd );
// Run it just to make sure it's working
oCmd.Execute();
// Now loop through the command collection and print the name and
// scripting name of each custom command
// (Tip: It is faster to use CommandCollection.Filter("Custom") to
// find all custom commands)
var eCmdList = new Enumerator( Application.Commands );
eCmdList.moveFirst();
var c;
for (; !eCmdList.atEnd(); eCmdList.moveNext() )
{
	c = eCmdList.item();
	if(!(c.Builtin))
	{
		LogMessage( c.Name + "(" + c.ScriptingName + ") is a custom command." );
	}
}

// Restore everything back to normal
Application.RemoveCommand("Howdy");
fso.DeleteFile( sFileName, true );
// --------------------------------------------------------------
// Output of the above script is:
//
//INFO : "Hello, World!"
//Howdy();
//Followed by a list of all custom commands installed, including:
//INFO : "Howdy is a custom command."

Related Examples

Command.1.js

Command.2.js

Command.3.js

Command.4.vbs

Keywords

Command Execute GetFlag SetFlag Update Arguments Builtin CannotBeUsedInBatch Category Code Description Enabled FileName Handler IsNotLogged Language ReturnValue ScriptingName SupportsKeyAssignment Tooltip UID


Autodesk Softimage 2011