CustomOperator.AddParameter

導入

v4.0

詳細

新しいカスタムParameterをカスタムオペレータに追加します。

カスタムオペレータのパラメータは、オペレータの動作を設定するときに使用すると便利です。パラメータは、通常はオペレータのPPGに表示されるので、ユーザはスライダおよび他のコントロールを移動することでオペレータを制御できます。パラメータ値への変更内容はオペレータに「ダーティ」されるので、次に出力が評価されるときに、再評価されます。

自己インストールカスタムオペレータの評価中は、OperatorContext.GetParameterValueからそのパラメータ値を使用できます。カスタムオペレータの他のタイプは、Operatorのパラメータプロパティを使用して読み取ることができます。このオペレータは以下の例に示すように、UpdateContext.Operatorを使用して取得できます。

スクリプト 構文

oReturn = CustomOperator.AddParameter( ParamDef );

戻り値

新しく作成されたParameterオブジェクト

パラメータ

パラメータ タイプ 詳細
ParamDef ParamDef この引数は、パラメータ定義を指定します。

JScript の例

/*
        This example illustrates how to add parameters to a custom operator
*/
NewScene( null, false )
var null1 = GetPrim( "null" );
// Create the operator
var sop = XSIFactory.CreateScriptedOp( "MySOP", MySOP_Update.toString(), "JScript" );
// Add the ports
sop.AddOutputPort( null1.posx );
// Add the parameters
var param1 = sop.AddParameter( XSIFactory.CreateParamDef2("text", siString, "hello") );
var param2 = sop.AddParameter( XSIFactory.CreateParamDef2("bool", siBool, true) );
var param3 = sop.AddParameter( XSIFactory.CreateParamDef2("int", siInt4, 10, 0, 100) );
var param4 = sop.AddParameter( XSIFactory.CreateParamDef2("dbl", siDouble, 0.5, 0.0, 1.0) );
// List operator's parameters
var eParams = new Enumerator( sop.Parameters );
for ( ; !eParams.atEnd(); eParams.moveNext() )
{
        var param = eParams.item();
        Application.LogMessage( param.Name + " = " + param.Value );
}
// Connect the operator
sop.Connect();
// Show the PPG of the operator which includes the parameters
InspectObj( sop ) ;
// The operator's update function
function MySOP_Update( ctx, out )
{
        // Normally we would do something with the parameters
        // but for the purpose of the demo just print the values
        oParams = ctx.Operator.Parameters ;
        Application.LogMessage( "MySOP_Update" ) ;
        Application.LogMessage( "   Text parameter: " + oParams( "text" ).Value ) ;
        Application.LogMessage( "   Bool parameter: " + oParams( "bool" ).Value ) ;
        Application.LogMessage( "   int parameter: " + oParams( "int" ).Value ) ;
        Application.LogMessage( "   double parameter: " + oParams( "dbl" ).Value ) ;
        out.Value = ctx.CurrentFrame;   
}

関連項目

CustomOperator.RemoveParameter XSIFactory.CreateParamDef Parameter ProjectItem.Parameters UpdateContext.Operator