ProjectItem.AddScriptedOpFromFile.1.js Example

Applies To

ProjectItem.AddScriptedOpFromFile method

Description

This example demonstrates how to use the ProjectItem.AddScriptedOpFromFile method.

Code

/*
	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;
}

Keywords

ProjectItem AddScriptedOpFromFile


Autodesk Softimage 2011