Command.3.js Example

Applies To

Command object

Description

JScript Custom Command overview - v1.5 Approach This example relies on a script on disk so you need to follow an important step first before running this example: SAVE the following commented out code as %XSI_USERHOME%\Data\Scripts\commandexample.js Once you have saved the file you can run the script

Code

/*
// BEGINNING OF CODE TO SAVE IN FILE
// 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") ;		
}
// END OF CODE TO SAVE IN FILE
*/

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() ;

	var fileNameWithPath = Application.InstallationPath( siUserPath ) + "/Data/Scripts/commandexample.js"
	//
	// Define Command #1 : CommandHelloWorld
	//
	var cmd = Application.CreateCommand( "CommandHelloWorld" )
	cmd.ScriptingName = "CommandHelloWorld" ;
	cmd.Language = "JScript" ;
	cmd.ReturnValue = false ;
	cmd.Handler = "HelloWorld" ; 
	cmd.FileName = fileNameWithPath;
	Application.AddCommand( cmd ) ;

	//
	// Define Command #2 : CommandSimple
	//
	cmd = Application.CreateCommand( "CommandSimple" )
	cmd.ScriptingName = "CommandSimple" ;
	cmd.Language = "JScript" ;
	cmd.ReturnValue = true ;
	cmd.Handler = "Simple" ; 
	cmd.FileName = fileNameWithPath;
	// 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.FileName = fileNameWithPath;
	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" ) ;	
}

Related Examples

Command.1.js

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