v4.0
新しいスクリプトオペレータを作成し、その出力をこのオブジェクトに接続します。スクリプトファイルが指定されていない場合には、デフォルトの実装が使用されます。スクリプト言語は省略できます。指定しない場合には、ファイル拡張子に関連付けられている言語が使用されます。これで言語が特定できない場合は、現在のスクリプト言語のユーザプリファレンスが使用されます。
CustomOperator ProjectItem.AddScriptedOpFromFile( String bszFileName, Object vInputs, String bszName, String bszLanguage, siConstructionMode in_constructionmode ); |
oReturn = ProjectItem.AddScriptedOpFromFile( [FileName], Inputs, [Name], [Language], [ConstructionMode] ); |
| パラメータ | タイプ | 説明 |
|---|---|---|
| FileName | String | スクリプト オペレータの実装を含むスクリプトのファイル名 |
| Inputs | List | 入力ポートに接続するオブジェクトまたはパラメータのリスト |
| Name | String |
新しいオペレータの名前 デフォルト値: ScriptedOp |
| Language | String |
新しいスクリプトオペレータのスクリプト言語 デフォルト値:application.preferences.scripting.language から取得した設定値 |
| ConstructionMode | siConstructionMode |
オペレータが作成されるコンストラクションスタックの位置。これは、Geometry オブジェクトに対して作成された出力接続にのみ適用されます。その他のすべての接続タイプではモードは無視されます。
デフォルト値:siConstructionModeDefault |
/*
This example creates a simple expression-like scripted operator
which constrains the rotation of one object to another
*/
NewScene( null, false );
var obj1 = GetPrim( "null" );
var obj2 = GetPrim( "null" );
// Create script file on disk
var filename = XSIUtils.BuildPath( Application.InstallationPath(siUserPath), "Data", "Scripts", "myexpr_sop.js" );
var fso = new ActiveXObject( "Scripting.FileSystemObject" );
var f = fso.CreateTextFile( filename, true );
f.Write( myexpr_Update.toString() );
f.Close();
// Apply operator
var col = XSIFactory.CreateActiveXObject( "XSI.Collection" );
col.Add( obj1.Kinematics.Global );
col.Add( obj2.Kinematics.Global );
obj1.Kinematics.Global.AddScriptedOpFromFile( filename, col, "myexpr", "JScript" );
function myexpr_Update( ctx, out, inglobal1, inglobal2 )
{
var transfo = inglobal1.Value.Transform;
var rot = XSIMath.CreateRotation();
inglobal2.Value.Transform.GetRotation(rot);
transfo.SetRotation( rot );
out.Value.Transform = transfo;
} |