AddScriptedOpFromFile

Introduced

v4.0

Description

Creates a runtime scripted operator whose definition is saved within the scene. A runtime scripted operator is one that is embedded within the scene and doesn't require the installation of a SPDL file or Self-Installed Custom Operator.

The implementation of the scripted operator comes from a specified file (on disk). To specify an implementation on the fly (eg., in a string variable), use the AddScriptedOp command instead. Once instantiated the operator will store a copy of the code and not refer to the contents of the specified file anymore.

Scripting Syntax

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

Return Value

Returns an CustomOperator that contains a runtime-designed scripted operator

Parameters

Parameter Type Description
OutputObjs List List of objects or parameters to connect the output ports too.
FileName String The script filename containing the implementation of the scripted operator.
InputObjs List List of objects or parameters to be connected to input ports.
Name String The name of the new operator

Default Value: ScriptedOp

Language String The script language of the operator.

Default Value: Value from Application.Preferences.Scripting.Language

ConstructionMode siConstructionMode Specifies which construction mode the operator will be applied. This only applies to output connections made to Geometry objects, the mode will be ignored for all other types of connections.

Default Value: Use the current construction mode

Examples

JScript Example

/*

	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;

//}"

See Also

ApplyOp AddScriptedOp AddCustomOp ConvertScriptedOp ProjectItem.AddScriptedOpFromFile CustomOperator