Operator.ConnectToGroup

Introduced

v4.0

Description

Connects an object to a port group. This method is useful for dynamic operators, where optional or multi-instance connections are made after the object is already connected.

Note: This method only works for Self-Installed Custom Operators if there is a single port inside the port group. This limitation exists because you can only pass a single object in the Object argument.

Scripting Syntax

oLong = Operator.ConnectToGroup( Group, Object );

Return Value

Long The index of new port group instance.

Parameters

Parameter Type Description
Group Long Which port group to connect
Object Object The object to be connected to the port. For built-in Operators this object can be a X3DObject and Softimage will attempt to find the correct data underneath the X3DObject to match each port inside the PortGroup. For Self-Installed Custom Operators this should be the specific target object for the port inside the PortGroup.

Examples

JScript Example

/*
        This example demonstrates how to connect a runtime custom operator to an object.
*/
NewScene( null, false );
var null1 = GetPrim( "null" );
var null2 = GetPrim( "null" );
// Create a runtime scripted operator and turn on debugging (logs extra information)
var sop = XSIFactory.CreateScriptedOp( "myexpr", myexpr_Update.toString(), "JScript" );
sop.Debug = 1;
// Add a portgroup to read from/write to
var group1 = sop.AddPortGroup( "MainGroup" )
// We use an IO port because we want to blend the existing
// transformation rather than completely replacing it
sop.AddIOPort( null1.Kinematics.Local, "", group1.Index );
// Add a second group with an optional port
var group2 = sop.AddPortGroup( "SecondGroup", 0, 1 )
sop.AddInputPort( null2.Kinematics.Local, "inputs", -1, group2.Index );
// Connect first group.  Operator would start functioning immediately
sop.ConnectToGroup( group1.Index, null1.Kinematics.Local );
// Connect to the optional port
sop.ConnectToGroup( 1, null2.Kinematics.Local);
// This has no effect on null1
Translate( null2, 1, -1, 1 );
// This changes null1 rotation as well
Rotate(null2, 90, -45, 0 ) ;
// This operator constrains the rotation of the connected (target) object to the
// rotation of the object connected through the second portgroup.
function myexpr_Update( ctx, out, inlocal1, inlocal2 )
{
        Application.LogMessage( "myexpr_Update: " + out.Name );
        Application.LogMessage( ""+(inlocal2) );
        var transfo = inlocal1.Value.Transform;
        // Is there an object connected to the 2nd group?
        if ( ctx.Operator.GetNumInstancesInGroup( 1 ) )
        {
                var inlocal2 = ctx.Operator.PortAt( 0, 1, 0 );
                // Is the port connected?
                if ( inlocal2.IsConnected )
                {
                        var rot = inlocal2.Value.Transform.Rotation;
                        transfo.SetRotation     ( rot );
                }
        }
        out.Value.Transform = transfo;
}

See Also

Operator.DisconnectGroup UpdateConnectOnOp