ArgumentCollection.AddWithHandler

導入

v4.0

詳細

引数とArgumentHandlerを追加します。

C#構文

Argument ArgumentCollection.AddWithHandler( String in_ArgumentName, Object in_ArgHandler, String in_DefaultValue );

スクリプト構文

oReturn = ArgumentCollection.AddWithHandler( ArgumentName, ArgumentHandler, [DefaultValue] );

戻り値

Argument

パラメータ

パラメータ タイプ 説明
ArgumentName String 追加する新しい引数の名前
ArgumentHandler siArgumentHandler 使用する引数ハンドラの名前
DefaultValue String 通常は引数ハンドラにはデフォルト値は不要ですが、文字列を指定した場合は動作を若干調整する必要があります。たとえば、"Collection"引数ハンドラに"*"という文字を組み合わせて使用すると、現在の選択対象ではなくシーン内のすべてのオブジェクトがコマンドに渡されます。この動作については、siArgumentHandlerを参照してください。

JScript の例

// 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"

関連項目

ArgumentHandler ArgumentCollection.Add Command.Arguments