Command.1.js Example

Applies To

Command object

Description

JScript Custom Command overview - Embedded Approach

Code

InstallCommands();
DemoCommands() ;
// Comment out this line if you want to experiment with the 
// commands created in this example
CleanupCommands();
function InstallCommands()
{
	// Remove any existing copies of the demo commands
	CleanupCommands() ;
	// each command needs to be defined.
	// (Softimage will not forget this information
	// until they are removed with a call to CleanupCommands() ;
	//
	// Define Command #1 : CommandHelloWorld
	//
	var cmd = Application.CreateCommand( "CommandHelloWorld" )
	cmd.ScriptingName = "CommandHelloWorld" ;
	cmd.Language = "JScript" ;
	cmd.ReturnValue = false ;
	cmd.Handler = "HelloWorld" ; 
	cmd.Code = HelloWorld.toString() ; // Embed the code directly in the definition
	Application.AddCommand( cmd ) ;

	//
	// Define Command #2 : CommandSimple
	//
	cmd = Application.CreateCommand( "CommandSimple" )
	cmd.ScriptingName = "CommandSimple" ;
	cmd.Language = "JScript" ;
	cmd.ReturnValue = true ;
	cmd.Handler = "Simple" ; 
	cmd.Code = Simple.toString() ; // Embed the code directly in the definition
	// You must mention the arguments you want.
	// The name is not important but must be unique
	cmd.Arguments.Add("a")
	cmd.Arguments.Add("b")	
	Application.AddCommand( cmd )
	//
	// Define Command #3 : CommandSimpleObjectArg
	//
	cmd = Application.CreateCommand( "CommandSimpleObjectArg" )
	cmd.ScriptingName = "CommandSimpleObjectArg" ;
	cmd.Language = "JScript" ;
	cmd.ReturnValue = true ;
	cmd.Handler = "SimpleObjectArg" ; 
	cmd.Code = SimpleObjectArg.toString() ; // Embed the code directly in the definition
	cmd.Arguments.AddObjectArgument("obj");
	Application.AddCommand( cmd )
}
function DemoCommands()
{
	// It is simple to execute a custom command, especially one
	// like this with no return value or arguments.
	// Will log "Hello World"
	CommandHelloWorld() ;
	// Will log "15"
	logmessage( CommandSimple( 5, 10 ) );
	// Will log "concat"
	logmessage( CommandSimple( "con","cat" ) ) ;
	newscene( null, false ) ;
	var oSphere = ActiveSceneRoot.AddGeometry("Sphere", "NurbsSurface") ;
	//Will log:
	//INFO : "Name of the input object sphere"
	//INFO : "grid"		
	logmessage( CommandSimpleObjectArg( oSphere ) ) ;
	//Softimage can also turn an string to an object:
	//INFO : "Name of the input object grid"
	//INFO : "grid1"
	logmessage( CommandSimpleObjectArg( "grid" ) ) ;
}
function CleanupCommands()
{
	Application.RemoveCommand( "CommandHelloWorld" ) ;
	Application.RemoveCommand( "CommandSimple" ) ;
	Application.RemoveCommand( "CommandSimpleObjectArg" ) ;	
}
// Implementation of CommandHelloWorld
// The name of this function matches the string we provided as cmd.Handler
function HelloWorld()
{
	LogMessage( "Hello World" ) ;
}
function Simple( in_a, in_b )
{
	return in_a + in_b ;
}
function SimpleObjectArg( in_obj )
{
	logmessage( "Name of the input object " + in_obj.Name ) ;	
	// return a different object
	return ActiveSceneRoot.AddGeometry("Grid", "MeshSurface") ;		
}

Related Examples

Command.2.js

Command.3.js

Command.5.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