Command.Update.1.js Example

Applies To

Command.Update method

Description

This example demonstrates how to use the Command.Update method.

Code

/* 
	This example demonstrates how to update a command definition
*/
var cmd = Application.CreateCommand("CustomCmd") ;
cmd.ScriptingName = "CustomCmd" ;
cmd.Handler = "CmdImpl" ; 
// Although we define the command with jscript
// the embedded code is vbscript!
cmd.Language = "JScript" ; 
cmd.Code = CmdImpl.toString() ;		   
Application.AddCommand( cmd ) ;
// Now the command has been added to Softimage
// but our definition doesn't match CmdImpl, 
// which expects an argument.
// If we try to call the custom command
// we see that things are not working properly
try
{
	// Logs: CmdImpl called: undefined
	CustomCmd(); 
	// Causes error "Wrong number of arguments..."
	CustomCmd(1); 
}
catch( e )
{
}

// Now fix the command
cmd = Commands.Item("CustomCmd");
// Add a new argument with a default value of 1.
cmd.Arguments.Add("Arg1", siArgumentInput, 1);
// Commit changes.  Please note that all the changes would be local to
// cmd if Update is not called.
cmd.Update();

//Logs: CmdImpl called: 1
CustomCmd(); 
//Logs: CmdImpl called: 24
CustomCmd(24); 

// Cleanup
Application.RemoveCommand( "CustomCmd" ) ;

// This is the implementation of the custom command		
function CmdImpl( arg1 )
{
	Logmessage( "CmdImpl called: " + arg1 ) ;
	return arg1 ;
}

Keywords

Command Update


Autodesk Softimage 2011