AddScriptedOpFromFile

導入

v4.0

詳細

シーン内にその定義を保存する、ランタイムのスクリプト オペレータを作成します。ランタイムのスクリプト オペレータとは、シーンに組み込まれ、SPDL ファイルのインストールや自己インストール カスタム オペレータを必要としないオペレータです。

スクリプト オペレータの実装は、ディスク上の指定のファイルから取得します。 ディスク上の実装ファイルを実行時に指定する場合(文字列変数を使用する場合など)は、代わりに AddScriptedOp コマンドを使用します。インスタンス化されると、オペレータはコードのコピーを保存し、指定されたファイルの内容は参照しなくなります。

スクリプト構文

oReturn = AddScriptedOpFromFile( OutputObjs, FileName, InputObjs, [Name], [Language], [ConstructionMode] );

戻り値

ランタイム用に設計されたスクリプト オペレータを含む CustomOperator を戻します。

パラメータ

パラメータ タイプ 説明
OutputObjs リスト 出力ポートの接続先となるオブジェクトまたはパラメータのリスト。
FileName 文字列 スクリプト オペレータの実装を含むスクリプトのファイル名
InputObjs リスト 入力ポートに接続するオブジェクトまたはパラメータのリスト
Name 文字列 新しいオペレータの名前

デフォルト値: ScriptedOp

Language 文字列 オペレータのスクリプト言語。

デフォルト値:Application.Preferences.Scripting.Language から取得した値

ConstructionMode siConstructionMode オペレータを適用するコンストラクション モードを指定します。 これは、Geometry オブジェクトに対して確立された出力接続にのみ適用されます。その他のすべての接続タイプでは、モードは無視されます。

デフォルト値:現在のコンストラクション モードを使用

JScript の例

/*

	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 set the contents of the new implementation file.

//

function fred_Update( ctx, out ) 

{ 

	LogMessage( "fred::Update()" );

	out.Value = 2;

}

// Create the script file on disk using the JScript FileSystemObject 

// utility (consult a JScript scripting guide for more details).

var file_loc = InstallationPath( siUserPath ) + "\\Data\\Scripts\\fred_sop.js";

var fso = new ActiveXObject( "Scripting.FileSystemObject" );

var ts = fso.CreateTextFile( file_loc, true );

ts.Write( fred_Update.toString() );

ts.Close();

// ------------------------------------------------------------

//

//	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 op = AddScriptedOpFromFile( "null.kine.local.posx", file_loc, 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 Code returns the

//	contents of the implementation file:

//

//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: <your_user_path>\Data\Scripts\fred_sop.js"

//INFO : "	Code: function fred_Update( ctx, out ) 

//{ 

//	LogMessage( "fred::Update()" );

//

//	out.Value = 2;

//}"

関連項目

ApplyOp AddScriptedOp AddCustomOp ConvertScriptedOp ProjectItem.AddScriptedOpFromFile CustomOperator