// JScript example: Add argument handler that gets the current selection
// Remove existing command
Application.RemoveCommand("MyCommand");
// Create a command named "MyCommand". You must create the file and paste
// the "MyCommandFunc" function in the file to get the example to work
var oCmd = Application.CreateCommand("MyCommand");
// Outputs all element that are currently selected
function MyCommandFunc( in_CurrentSelection )
{
Logmessage( "MyCommandFunc was called with the following arguments: " ) ;
for (i = 0; i < in_CurrentSelection.Count; i++ )
{
var currentItem = in_CurrentSelection(i);
LogMessage( currentItem.Name );
}
}
// Set the handler code (this is an embedded command)
oCmd.Code = MyCommandFunc.toString() ;
oCmd.Language = "Jscript" ;
// Function implementing the handling code (see MyCommandFunc for the actual function code)
oCmd.Handler = "MyCommandFunc";
// Adds an argument handler that gets the currently selected objects
// when the user does not specify the argument value when invoking the
// command.
var oCmdArguments = oCmd.Arguments
var noValue;
oCmdArguments.AddWithHandler
(
"CurrentSelection", // name of the new argument
"Collection", // name of the argument handler to use
noValue // parameter to the argument handlers (stored in Argument.Value)
);
// Register the new command
Application.AddCommand(oCmd);
SelectObj( "light" ) ;
// Call the updated command. The "CurrentSelection" argument
// will contain the current selection.
oCmd.Execute();
// You can override the behavior by passing specific object
oCmd.Arguments(0).Value = "Camera_Root" ;
oCmd.Execute() ;
// Remove the command
Application.RemoveCommand("MyCommand");
// Expected results:
//INFO : "MyCommandFunc was called with the following arguments: "
//INFO : "light"
//INFO : "MyCommandFunc was called with the following arguments: "
//INFO : "Camera_Root"
|