ArgumentCollection.Add

説明

Commandの定義に引数を追加します。

オブジェクト呼び出しを受け取る引数を追加する場合は、代わりにArgumentCollection.AddObjectArgumentを使用します。ArgumentHandlerを使用する場合は、代わりにArgumentCollection.AddWithHandlerを使用します。このメソッドは、カスタムコマンドでのみ使用できます。通常、このメソッドはコマンドの定義中(XSIApplication.AddCommandが呼び出される前)に呼び出されます。ただし、引数を追加してCommand.Updateを呼び出し、既存のコマンドを変更することもできます。

C#構文

Argument ArgumentCollection.Add( String Name, siArgumentFlags argflags, Object defval, siVariantType in_vtValType );

スクリプト構文

ArgumentCollection.Add( Name, [Flags], [Value], [ArgType] );

パラメータ

パラメータ タイプ 説明
Name String 引数の名前。ArgumentCollection内でユニークな名前が指定されている場合は、ここで選択する特定の名前はあまり重要ではありません。ただし、適切な引数名を指定することで、Commandの使用法を理解しやすくなります。スクリプトベースのカスタムコマンドの場合は、実装での対応する引数の名前と同じでなくてもかまいません。
Flags siArgumentFlags 現時点では、カスタムコマンドでサポートされている値は siArgumentInput だけです。

デフォルト値:siArgumentInput

Value Variant 引数のデフォルト値(無指定の場合のデフォルト)。デフォルト値を指定することは、要求される特定の VARIANT 型を指定することと同じです(siVariantTypeを参照)。たとえば、デフォルト値が倍精度の場合は、Softimage はコマンドを呼び出す前にすべての入力引数を倍精度に変換しようと試みます。デフォルト値を指定しなければ、引数は変換は行われずに直接渡されます。
ArgType siVariantType 引数値の型は、デフォルトでは siEmpty です。

この引数は、通常の Variant 値(文字列、整数、倍精度、配列)である引数に対して任意に指定します。ただし、引数がオブジェクトを参照するポインタであることを指定するには、この引数を siDispatch に設定し、Value 引数を0 に設定する必要があります(より簡単な方法は、代わりにArgumentCollection.AddObjectArgumentを使用することです)。

Jscript オブジェクトまたは JScript Array を受け取るように引数を指定する場合は、以下の例に示すように siDispatch を指定します。

デフォルト値:siEmpty

JScript の例

/*

	This is an advanced JScript example showing how to use the powerful jscript

	class and array features in conjunction with Softimage Custom Commands.

	When a jscript plugin becomes very large it can be necessary to split the 

	code into multiple self-installed plugin script files and to organize the

	code into classes.  This example shows how you can pass JScript objects and 

	arrays back and forth between these files via Softimage Custom Commands.

*/ 

var strCmdName = "TestJScriptArgs"

var oCmd = Application.CreateCommand( strCmdName  )

oCmd.ScriptingName = strCmdName  ;

// For demonstration purposes this is an embedded command.

// 

// We need to copy the implementation of JScriptClass as well as the implementation 

// of the command so that JSCmdImpl can instantiate this class as the return value

oCmd.Code = JSCmdImpl.toString() 

		+ JScriptClass.toString()

		+ JScriptClass_Foo.toString() ;

oCmd.Handler = "JSCmdImpl" ;

oCmd.Language = "JScript" ;

// You cannot print out a jscript object or a jscript array.  This is ok because

// printing out large arrays would slow down execution of your script.

oCmd.SetFlag(siNoLogging) ; 

// It is critical to specify siDispatch, otherwise Softimage will attempt

// to convert the jscript object into a SAFEARRAY

oCmd.Arguments.Add( "JSObjArg", siArgumentInput, 0, siDispatch ) ;	

// For normal custom command development this is the way to specify an array 

// argument.  But this means the array will be converted to a SAFEARRAY 

// (also called vbarray). This is important if you want your custom command

// to be available to all other scripting languages and C++ API

oCmd.Arguments.Add( "JSArrayToVBArray", siArgumentInput ) ;	

// If you only want your custom command to be available from other jscript 

// code then you can get better speed by passing the JScript array 

// untouched by specifying siDispatch

oCmd.Arguments.Add( "JSArrayUnconverted", siArgumentInput, 0, siDispatch ) ;

Application.AddCommand( oCmd ) ;

// Create some data to pass to the command

var oObj = new JScriptClass( 12 ) ;

var jsarray = new Array( "A", 89, 2.5, "banana" ) ;

// Invoke the command (which calls JSCmdImpl)		

var oRetVal = TestJScriptArgs(oObj,jsarray,jsarray) ;

// Demonstrate that calling the command actually changed

// MemberVar from 12 to 13

logmessage( "oObj.MemberVar = " + oObj.MemberVar ) ;

// Demonstrate that the command returned a jscript object

logmessage( "oRetVal.MemberVar = " + oRetVal.MemberVar ) ;

Application.RemoveCommand( strCmdName  ) ;

// Simple jscript class

function JScriptClass( in_x )

{

	// Remember the constructor argument

	// as a member variable

	this.MemberVar = in_x ;

	// function

	this.Foo = 	JScriptClass_Foo ;

}

// Function used as a method of JScriptClass

function JScriptClass_Foo()

{

	return "Foo called" ;

}

// Custom command Implementation

function JSCmdImpl(in_jscriptObj, in_vbarg, in_jsarg)

{	

	logmessage( "JSCmdImpl called" ); 

	// Demonstrate that we really have an instance of JScriptClass

	logmessage( "in_jscriptObj.MemberVar = " + in_jscriptObj.MemberVar ) ;

	logmessage( "in_jscriptObj.Foo function = " + in_jscriptObj.Foo() ) ;

	// We can also change the content of the object passed to us

	// and the caller will see the change.  This is an excellent

	// way to share data between different script files	

	in_jscriptObj.MemberVar = 13 ;

	// For a safearray we need to convert it (back) to 

	// a JScript array.  This is our only choice

	// if we want the command to be called from vbscript

	backAsJS = new VBArray( in_vbarg ).toArray(); 

	logmessage( "in_vbarg[2] = " + backAsJS[2] ) ;

	// Demonstrate that we really have a JScript array

	logmessage( "in_jsarg[3] = " + in_jsarg[3] ) ;

	// You can also return a JScript object

	return new JScriptClass( 1000 ) ;

}

//Expected output:

//INFO : JSCmdImpl called

//INFO : in_jscriptObj.MemberVar = 12

//INFO : in_jscriptObj.Foo function = Foo called

//INFO : in_vbarg[2] = 2.5

//INFO : in_jsarg[3] = banana

//INFO : oObj.MemberVar = 13

//INFO : oRetVal.MemberVar = 1000

関連項目

XSIApplication.CreateCommand Command ArgumentCollection ArgumentCollection.AddObjectArgument ArgumentCollection.AddWithHandler Argument