v4.0
シーン内にその定義を保存する、ランタイムのスクリプト オペレータを作成します。ランタイムのスクリプト オペレータとは、シーンに組み込まれ、自己インストールのコールバックや SPDL ファイルのインストールを必要としないオペレータです。
スクリプト オペレータの実装は Code パラメータ内に保存される文字列を使用して定義します。 ディスク上の実装ファイルを指定する場合は、代わりに AddScriptedOpFromFile または AddCustomOp を使用します。
oReturn = AddScriptedOp( OutputObjs, [Code], InputObjs, [Name], [Language], [ConstructionMode] ); |
ランタイム用に設計されたスクリプト オペレータを含む CustomOperator を戻します。
| パラメータ | タイプ | 説明 |
|---|---|---|
| OutputObjs | リスト | 出力ポートの接続先となるオブジェクトまたはパラメータのリスト。 |
| Code | 文字列 | スクリプト オペレータの実装を含むスクリプト。 |
| InputObjs | リスト | 入力ポートの接続先となるオブジェクトまたはパラメータのリスト。 |
| Name | 文字列 |
新しいオペレータの名前 デフォルト値: ScriptedOp |
| Language | 文字列 |
オペレータのスクリプト言語。 デフォルト値:Application.Preferences.Scripting.Language から取得した値 |
| ConstructionMode | siConstructionMode |
オペレータを適用するコンストラクション モードを指定します。 これは、Geometry オブジェクトに対して確立された出力接続にのみ適用されます。その他のすべての接続タイプでは、モードは無視されます。
デフォルト値:現在のコンストラクション モードを使用 |
/*
This example demonstrates how to create and connect a scripted operator
that constrains the local posx of an object to the value of 2.
*/
// ------------------------------------------------------------
//
// This is an easy way to specify the code as a string:
// define it as a regular function as part of this
// example and then use the JScript function toString()
// to save the function as a string variable that we
// can assign to the Code parameter of the AddScriptedOp
// command.
//
function fred_Update( ctx, out )
{
LogMessage( "fred::Update()" );
out.Value = 2;
}
// ------------------------------------------------------------
//
// Set up the null and apply the scripted operator to
// its posx parameter. Print the value of the posx
// parameter before and after.
//
// Create scene and apply operator
NewScene( null, false );
GetPrim( "null" );
// Get the value of posx before applying the operator
Application.LogMessage( "posx = " + GetValue( "null.kine.local.posx" ) );
// Create and apply the operator to the null's posx
var str = fred_Update.toString();
var op = AddScriptedOp( "null.kine.local.posx", str ,null,"fred" );
// Get the constrained value
Application.LogMessage( "posx = " + GetValue( "null.kine.local.posx" ) );
// ------------------------------------------------------------
//
// Since the scripted operator is returned, we can use
// the methods and properties of the Operator object.
//
// Log details of operator
Application.LogMessage( "Scripted Operator: " + op.FullName );
Application.LogMessage( "\tClassName: " + ClassName(op) );
Application.LogMessage( "\tType: "+ op.Type );
Application.LogMessage( "\tLanguage: "+ op.Language );
Application.LogMessage( "\tAlwaysEvaluate: "+ op.AlwaysEvaluate );
Application.LogMessage( "\tDebug: "+ op.Debug );
Application.LogMessage( "\tMute: "+ op.Mute );
Application.LogMessage( "\tFileName: "+ op.FileName );
Application.LogMessage( "\tCode: "+ op.Code );
// ------------------------------------------------------------
//
// Output of this example. Notice that FileName returns
// nothing because the code has been defined on the fly:
//
//INFO : "posx = 0"
//
//INFO : "fred::Update()"
//INFO : "posx = 2"
//INFO : "Scripted Operator: null.kine.local.fred"
//INFO : " ClassName: CustomOperator"
//INFO : " Type: fred"
//INFO : " Language: JScript"
//INFO : " AlwaysEvaluate: false"
//INFO : " Debug: 0"
//INFO : " Mute: false"
//INFO : " FileName: "
//INFO : " Code: function fred_Update( ctx, out )
//{
// LogMessage( "fred::Update()" );
//
// out.Value = 2;
//}" |