AddScriptedOp

Introduced

4.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 self-installing callbacks or the installation of SPDL file.

The implementation of the scripted operator is defined using a string saved in the Code parameter. To specify an implementation file on disk, use AddScriptedOpFromFile or AddCustomOp instead.

Scripting Syntax

    AddScriptedOp( OutputObjs, [Code], InputObjs, [Name], [Language], [ConstructionMode] )

Parameters

Parameter | Type | Description
OutputObjs | List | List of objects or parameters to connect the output ports to.
Code | String | The script containing the implementation of the scripted operator.
InputObjs | List | List of objects or parameters to connect the input ports to.
Name | String | The name of the new operator Default Value: ScriptedOp
Language | String | The script language of the operator fo 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

Return Value

Returns an CustomOperator that contains a runtime-designed scripted operator

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

See Also

ApplyOp | AddScriptedOpFromFile | ConvertScriptedOp | AddCustomOp
ProjectItem.AddScriptedOp | CustomOperator |  |

Autodesk Softimage v7.5