Object Hierarchy | 関連する C++クラス:Argument
Arguments
v2.0
Argument オブジェクトは、SoftimageCommand の引数(またはパラメータ)です。たとえば、DeleteObjコマンドは 1 つの引数("InputObj")を取ります。ArgumentCollection.Add、ArgumentCollection.AddWithHandler、またはArgumentCollection.AddObjectArgumentメソッドを使用して、カスタムコマンドに引数を追加します。
Argument オブジェクトは Softimage で 3 つの状況で使用されます。
- コマンドの作成時にコマンド引数を定義します。コマンドが作成されると、引数が Command オブジェクトに追加され、その引数のデフォルト値を定義するために Argument.Value が設定されます。デフォルト値は変動しません。コマンドを呼び出す際に値を指定しない場合はデフォルト値が引数として使用されます。
- コマンドを呼び出す際に引数値を指定します。コマンドが呼び出されると、コマンドに渡される引数値の指定にArgument.Valueが使用されます。また、ArgumentHandlerを定義すると、選択対象やシーンの内容に基づいてデフォルト値を取得できます。ArgumentCollection.AddWithHandlerメソッドを使用し、ハンドラを持つ引数を作成できます。
- カスタムコマンドをインストールした後に、カスタムコマンドの定義を変更できます。この場合は、Argument.Valueによりコマンドの新しいデフォルト値を指定できるほか、引数の追加と削除を実行できます。その後、変更を反映するためにCommand.Updateが呼び出されます。
カスタムコマンドの作成手順については、Commandオブジェクトを参照してください。
| Application | Categories | Flags | FullName |
| Handler | Help | Name | NestedObjects |
| Origin | OriginPath | Parent | Type |
| Value | |||
/* ------------------------------------------------------------------------------
This JScript example demonstrates how to create a command with
arguments and then how to pass values to the command when executing it.
------------------------------------------------------------------------------ */
// Start off with a clean slate
Application.RemoveCommand( "SillyPutty" );
// Get the user path and use it to build the filename + path
sFileName = InstallationPath( siUserPath ) + "\\Data\\Scripts\\MySillyPutty.js";
// Create the script on disk
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var fHWFile = fso.CreateTextFile( sFileName );
fHWFile.WriteLine( "function OnSillyPutty( gooey, mute )" );
fHWFile.WriteLine( "{" );
fHWFile.WriteLine( "\tLogMessage( \"SillyPutty is working!\" );" );
fHWFile.WriteLine( "\tLogMessage( gooey );" );
fHWFile.WriteLine( "\tLogMessage( mute );" );
fHWFile.WriteLine( "}" );
fHWFile.Close();
// Create the custom command
var oCmd = CreateCommand( "SillyPutty", siNoCategory );
oCmd.Description = "Stretches and bends until it reaches the breaking point.";
oCmd.ScriptingName = "SillyPutty";
oCmd.Handler = "OnSillyPutty";
oCmd.FileName = sFileName;
oCmd.Language = "JScript";
// Add some arguments
var oArgs = oCmd.Arguments;
oArgs.Add( "Gooeyness", siArgumentInput, 24.0, siDouble );
oArgs.Add( "Mute", siArgumentInput, false, siBool );
// Register the new command
AddCommand( oCmd );
// Populate the arguments and run the command
var oRunCmd = Application.Commands( "SillyPutty" );
oRunCmd.Arguments(0).Value = 50.0;
oRunCmd.Arguments(1).Value = true;
oRunCmd.Execute();
/* ------------------------------------------------------------------------------
Output of above command:
INFO : "SillyPutty is working!"
INFO : "50"
INFO : "True"
SillyPutty(50, true, null);
------------------------------------------------------------------------------ */ |
'vbscript Custom Command Demo
'
'This script demontrates the Softimage support for creating a custom command and handling its
'arguments.
'
'This example uses an embedded command.
'When you run this script the following results will be logged in the script history:
' INFO : "Installing example command found in c:/temp/CmdDemo.vbs"
' INFO : "Default arguments for command are : DefaultString 2.2"
' INFO : "ExampleCommand is now installed"
' INFO : "ExampleCommand called - DefaultString 2.2"
' INFO : "ExampleCommand called - Another string 1.1"
dim cmd
'Remove any existing earlier registrations of this command
if ( typename( Application.Commands( "ExampleCommand" ) ) = "Command" ) then
Application.RemoveCommand "ExampleCommand"
end if
set cmd = Application.CreateCommand("ExampleCommand", siNoCategory)
cmd.Description = "Example custom command"
cmd.ScriptingName = "ExampleCommand"
cmd.Handler = "OnExampleCommand"
cmd.Code = _
"function OnExampleCommand( StringArg, DblArg ) " & vbCrLf & _
" 'Show the arguments we recieved" & vbCrLf & _
" LogMessage ""ExampleCommand called - "" & StringArg & "" "" & DblArg" & vtCrLf & _
" 'Return this value" & vbCrLf & _
" OnExampleCommand = 55 " & vbCrLf & _
"end function"
cmd.Language = "VBScript"
'Command is function, not a sub
cmd.ReturnValue = true
cmd.Arguments.Add "StringArg", siArgumentInput, "DefaultString"
cmd.Arguments.Add "DblArg", siArgumentInput, 2.2
logmessage "Default arguments for command are : " & cmd.Arguments(0).Value & " " & cmd.Arguments(1).Value
Application.AddCommand cmd
logmessage "ExampleCommand is now installed"
'Now that the command is installed we can look it up and execute it
set cmdlookup = Application.Commands("ExampleCommand")
'This will execute it with default values
cmdlookup.execute
'Use these specific values
cmdlookup.arguments(0).Value = "Another string"
cmdlookup.arguments(1).Value = 1.1
cmdlookup.execute |
'VBScript example
set args = Application.Commands("Twist").Arguments
for each a in args
LogString = a.Name & ":"
if a.Flags = siArgumentInput or a.Flags = siArgumentInputOutput then
LogString = LogString & CStr(a.Value)
end if
LogMessage LogString
next |