ArgumentHandler

ArgumentHandler

Object Hierarchy | 関連する C++クラス:ArgumentHandler

継承

SIObject

ArgumentHandler

導入

v4.0

詳細

引数ハンドラは、コマンドに渡す値を決定する際に役立つオブジェクトです。明示的に引数を指定しないでコマンドを呼び出した場合、または、コマンドへの送信前に与えられた引数に何らかの処理を施さなければならない場合は、引数ハンドラが起動します。たとえば、"Collection"引数ハンドラは、文字列のオブジェクトリストをそれらのオブジェクトを表すXSICollectionに変換します。

引数ハンドラはビルトインコマンドで幅広く使用され、カスタムコマンドに指定できます(「ArgumentCollection.AddWithHandler」を参照)。柔軟なカスタムコマンドの実装が容易になり、コマンド実装に必要なエラー処理の量を軽減します。

コマンド定義の一部として指定された引数ハンドラは、コマンドの呼び出し中にシーンのバックグラウンドで動作します。コーラー、実装ともに、ArgumentHandler オブジェクトを明示的に操作する必要はありません。

注:内部的には、引数ハンドラの状態は引数値に保存されます。このため、Argument.Handlerを呼び出すと、既存のArgument.Valueがすべてクリアされます。

メソッド

IsClassOfオペレータ IsEqualToオペレータ    
       

プロパティ

Application Categories FullNameオペレータ Help
Nameオペレータ NestedObjects Origin OriginPath
Parent Typeオペレータ    
       

JScript の例

//Jscript example demonstrating how to use the Argument Handlers.

//It also shows how the implementation of Custom Command can

//be embedded directly inside the definition.

RemoveCommands() ;

InstallCommands() ;	

DemoCommands() ;

function DemoCommands()

{

	// First set up a little scenario to

	// show how the arg handlers will react

	newscene(null,false) ;

	var oGrid1 = ActiveSceneRoot.AddGeometry( "Grid","MeshSurface","G1" ) ;

	var oGrid2 = ActiveSceneRoot.AddGeometry( "Grid","MeshSurface","G2" ) ;

	var oGrid3 = ActiveSceneRoot.AddGeometry( "Grid","MeshSurface","G3" ) ;

	SelectObj( oGrid1 ) ;

	/////////////////////////////////////////////////////////////

	// Collection Arg Handler

	/////////////////////////////////////////////////////////////

	//If we provide no argument then the current selection

	//is passed as the argument:

	DemoCollectionArgHandler() ;

	//Result:

	//INFO : "DemoCollectionArgHandler called with 1 items"

	//INFO : "		Item 0 : G1"

	// Also very useful for turning string names of objects into

	// an XSICollection

	DemoCollectionArgHandler( "G1,G2" );

	//Result:

	// "DemoCollectionArgHandler called with 2 items"

	// "		Item 0 : G1"

	// "		Item 1 : G2"

	/////////////////////////////////////////////////////////////

	// SingleObj Arg Handler

	/////////////////////////////////////////////////////////////

	// The SingleObj arg handler is very

	// useful for converting from

	// a string to a object.  This is widely

	// used in Softimage internal commands

	DemoSingleObjArgHandler( "G1" ) ;

	//Result: "DemoSingleObjArgHandler called with G1(Type: polymsh)"

	// Of course if you already have the object pointer it

	// is identical to the above call, but even faster to do this:

	// In this case the arg handler has nothing to do:

	DemoSingleObjArgHandler( oGrid1 ) ;

	//Result: "DemoSingleObjArgHandler called with G1(Type: polymsh)"

	/////////////////////////////////////////////////////////////

	// FrameRate Arg Handler

	/////////////////////////////////////////////////////////////

	// Change the current framerate to film (24fps)

	SetValue("PlayControl.Format", 7, null);

	DemoFrameRateArgHandler() ;

	//Result : "DemoFrameRateArgHandler called with 24"

	// If you call with an specific value then

	// the ArgHandler does nothing

	DemoFrameRateArgHandler( 12.5 ) ;

	//Result : "DemoFrameRateArgHandler called with 12.5"

	/////////////////////////////////////////////////////////////

	// Frame Arg Handler

	/////////////////////////////////////////////////////////////

	SetValue("PlayControl.Current", 33, null);

	// This arghandler is very useful for commands

	// that normally operate on the current frame

	// but which could also be used to process a different

	// frame.

	//

	// By default the current frame is passed as the argument

	DemoFrameArgHandler() ;

	//Result : "DemoFrameArgHandler called with 33"

	// but the user can override

	DemoFrameArgHandler( 99 ) ;

	/////////////////////////////////////////////////////////////

	// MarkedParameters ArgHandler

	/////////////////////////////////////////////////////////////

	// This handler is very useful for collecting information

	// about which parameters have been marked on the currently

	// Selected objects

	//

	// Select the name and subdivu parameters on all three grids

	SelectObj( oGrid1 ) ;

	AddToSelection( oGrid2 ) ;

	AddToSelection( oGrid3 ) ;

	SetMarking( "Name" ) ;

	AddToMarking( "polymsh.geom.subdivu" ) ;

	// Remove G2 from the list, to demonstrate that even though

	// it also has marked parameters these are not passed in

	RemoveFromSelection( oGrid2 ) ;

	DemoMarkedParametersArgHandler() ;

	//Results:

	// "		Item 0 : G1.Name"

	// "		Item 1 : G1.polymsh.geom.subdivu"

	// "		Item 2 : G3.Name"

	// "		Item 3 : G3.polymsh.geom.subdivu"

	//and the command is logged in the history like this:

	//DemoMarkedParametersArgHandler("G1.Name,G1.polymsh.geom.subdivu,G3.Name,G3.polymsh.geom.subdivu");

	// You can also pass the marked parameters as a string.

	var bigMarkingString = "G1.Name," +

						  "G1.polymsh.geom.subdivu," +

						  "G2.Name," +

						  "G2.polymsh.geom.subdivu," +

						  "G3.Name," +

						  "G3.polymsh.geom.subdivu"		

	DemoMarkedParametersArgHandler(bigMarkingString);	

	// There is a short form using the "/" character

	// which is equivalent to the previous call:

	DemoMarkedParametersArgHandler("G1,G2,G3/name,polymsh.geom.subdivu");

	//Results:	

	// "DemoMarkedParametersArgHandler called with 6 items"

	// "		Item 0 : G1.Name"

	// "		Item 1 : G1.polymsh.geom.subdivu"

	// "		Item 2 : G2.Name"

	// "		Item 3 : G2.polymsh.geom.subdivu"

	// "		Item 4 : G3.Name"

	// "		Item 5 : G3.polymsh.geom.subdivu"

	/////////////////////////////////////////////////////////////

	// MarkedParameters ArgHandler

	/////////////////////////////////////////////////////////////

	// This handler is almost exactly the same as the 

	// MarkedParameter arg handler, except that it

	// will strip out the non-animatable parameters

	// that have been marked.  In this case it doesn't

	// pass the "G1.Name" and "G3.Name" parameters that have been

	// marked

	DemoAnimatableParametersArgHandler() ;	

	//Results:	

	// "DemoMarkedParametersArgHandler called with 2 items"

	// "		Item 0 : G1.polymsh.geom.subdivu"

	// "		Item 1 : G3.polymsh.geom.subdivu"

	//You can also pass a string and the same sort of 

	//shortcut works:

	DemoAnimatableParametersArgHandler("G1.polymsh.geom/subdivu,subdivv") ;	

	//Results:	

	// "DemoMarkedParametersArgHandler called with 2 items"

	// "		Item 0 : G1.polymsh.geom.subdivu"

	// "		Item 1 : G1.polymsh.geom.subdivv"

}

function RemoveCommands()

{

	Application.RemoveCommand( "DemoCollectionArgHandler" ) ;

	Application.RemoveCommand( "DemoSingleObjArgHandler" ) ;

	Application.RemoveCommand( "DemoFrameRateArgHandler" ) ;

	Application.RemoveCommand( "DemoFrameArgHandler" ) ;

	Application.RemoveCommand( "DemoMarkedParametersArgHandler" ) ;

	Application.RemoveCommand( "DemoAnimatableParametersArgHandler" ) ;

}

function InstallCommands()

{

	InstallArgDemoCommand( 

		"DemoCollectionArgHandler", 

		"Collection",

		OnDemoCollectionArgHandler.toString() ) ;

	InstallArgDemoCommand( 

		"DemoSingleObjArgHandler", 

		"SingleObj",

		OnDemoSingleObjArgHandler.toString() ) ;

	InstallArgDemoCommand( 

		"DemoFrameRateArgHandler", 

		"FrameRate",

		OnDemoFrameRateArgHandler.toString() ) ;

	InstallArgDemoCommand( 

		"DemoFrameArgHandler", 

		"Frame",

		OnDemoFrameArgHandler.toString() ) ;

	InstallArgDemoCommand( 

		"DemoMarkedParametersArgHandler", 

		"MarkedParameters",

		OnDemoMarkedParametersArgHandler.toString() ) ;

	InstallArgDemoCommand( 

		"DemoAnimatableParametersArgHandler", 

		"AnimatableParameters",

		OnDemoAnimatableParametersArgHandler.toString() ) ;

}

function InstallArgDemoCommand( in_Name, in_ArgHandlerName, in_Code )

{

	var oCmd = Application.CreateCommand( in_Name ) ;

	// Same as ScriptName

	oCmd.ScriptingName = in_Name ;	

	// Same of the routine to call inside the "in_Code" argument

	// We use a naming scheme based on command name

	oCmd.Handler = "On" + in_Name ; 

	// Embed the code rather than referring to file

	oCmd.Code = in_Code ;		

	oCmd.Language = "JScript" ;

	oCmd.ReturnValue = true ;

	oCmd.Arguments.AddWithHandler( "Arg", in_ArgHandlerName ) ;

	Application.AddCommand( oCmd ) ;

}

//

// Command implementations

//

function OnDemoCollectionArgHandler( in_arg )

{

	// We recieve a Selection object or an

	// XSICollection.  In either case we use the Count and Item

	// properties to access the items.

	Logmessage( "DemoCollectionArgHandler called with " + in_arg.Count + " items" ) ;

	for ( i = 0 ; i < in_arg.Count ; i++ )

	{

		Logmessage( "\t\tItem " + i + " : " + in_arg.Item(i).FullName ) ;

	}

	return in_arg ;

}

function OnDemoSingleObjArgHandler( in_arg )

{

	Logmessage( "DemoSingleObjArgHandler called with " + in_arg.Name + 

				"(Type: " + in_arg.Type + ")" ) ;

	return in_arg ;

}

function OnDemoFrameRateArgHandler( in_arg )

{

	// Unless the user calls with a specific value for the argument

	// we get the current frame rate

	Logmessage( "DemoFrameRateArgHandler called with " + in_arg ) ;

	return in_arg ;

}

function OnDemoFrameArgHandler( in_arg )

{

	// Unless the user calls with a specific value for the argument

	// we get the current frame rate

	Logmessage( "DemoFrameArgHandler called with " + in_arg ) ;

	return in_arg ;

}

function OnDemoMarkedParametersArgHandler( in_arg )

{

	// We recieve a XSICollection with the Marked parameters 

	// on the selected objects

	Logmessage( "DemoMarkedParametersArgHandler called with " + in_arg.Count + " items" ) ;

	for ( i = 0 ; i < in_arg.Count ; i++ )

	{

		Logmessage( "\t\tItem " + i + " : " + in_arg.Item(i).FullName ) ;

	}

	return in_arg ;

}

function OnDemoAnimatableParametersArgHandler( in_arg )

{

	// We recieve a XSICollection with the Animatable Marked parameters 

	// on the selected objects

	Logmessage( "DemoMarkedParametersArgHandler called with " + in_arg.Count + " items" ) ;

	for ( i = 0 ; i < in_arg.Count ; i++ )

	{

		Logmessage( "\t\tItem " + i + " : " + in_arg.Item(i).FullName ) ;

	}

	return in_arg ;

}

関連項目

Command Argument ArgumentCollection