## ApplyGenOp

### Introduced

v4.0

### Description

Applies a generator operator and returns the newly created operator(s). (A generator operator is an operator which creates new geometry, such as the Loft, CrvStitch, and SrfFillet operators.) The newly generated objects are also available via one of the following methods:
(1) Use the output argument OutputObjs (only available for VBScript because most languages cannot cope with both an output argument and a return value--see the note below).
(2) Use Operator.OutputPorts first on the output operator and then use Port.Target2 on an item of the returned collection (as demonstrated in the JScript example below.
Warning: If you use the OutputPorts/Target2 method of getting the newly generated objects, remember that you can only access the output ports on an operator if it was applied in persistent mode (ie., don't freeze it until you get a pointer to the target object).
You can also use the generic ApplyOp command to apply a generator operator; however, if you want to hide or delete the input objects (original geometry) or you want the new geometry to be a polymsh, you must use this command.
Note: This command uses output arguments. C# and some scripting languages (such as JScript, PerlScript and Python) don't support arguments passed by reference. Normally you can get the output arguments via either XSIApplication.ExecuteCommand method (C#) or the ISIVTCollection (scripting languages), but this command already returns a value.
The only available workaround in this case is to create a VBScript custom command which returns both the output arguments and the return value in one array. For details, see What Happens when the Function Already Returns a Value?.

### Scripting Syntax

    oReturn = ApplyGenOp( PresetObj, [Target], [ConnectionSet], [ConnectType], [ImmediateMode], [GenOpInputsDisposal], [OutputObjs] );

### Return Value

Returns an XSICollection that contains the newly created operators.
Note: If you apply the operator in ImmediateMode (which immediately freezes it), you still get a collection of the operators applied, but they are invalid (not connected to anything in the scene).

### Parameters

Parameter | Type | Description
--- | --- | ---
PresetObj | String or a preset object (see SIGetPreset) | Generator and Converter Operators
Target | String | Geometry type of the output surface for the following surface-from-curves types of operators: "Birail", "CrvNet", "Extrusion", "ExtrusionAlongAxis", "ExtrusionTwoProfiles", "FourSided", "Loft", "Revolution", and "RevolutionAroundAxis" Default Value: NurbsSurface
Possible Values: | Description:
MeshSurface | Mesh surface geometry
NurbsSurface | Nurbs surface geometry
ConnectionSet | ConnectionSet | Specifies the objects connected to an operator. See OpPreset for details on the connection set required for the specific operator you are using. Note: Because this is an in/out parameter, any string (variable or value) you pass into this parameter is automatically converted to a ConnectionSet. Default Value: Currently selected objects are used as the main group. Warning: An error occurs if the connection set is invalid. Please verify the connection set required for the operator you are using to avoid breaking your scripts.
ConnectType | siBranchFlag | Specifies the type of connection (node or branch). Default Value: siUnspecified
ImmediateMode | siOperationMode | Specifies whether or not the operator should be immediately frozen. Default Value: siPersistentOperation
GenOpInputsDisposal | siGeneratorInputsDisposalMode | Specifies what to do with the input objects after the operation is performed. Default Value: siKeepGenOpInputs
Possible Values: | Description:
siKeepGenOpInputs | The inputs will be kept
siHideGenOpInputs | The inputs will be hidden
siDeleteGenOpInputs | The inputs will be deleted
OutputObjs | XSICollection | Returns a collection of X3DObject object(s) created by the generator operator.

### Examples

#### 1. JScript Example

    /*
            This example demonstrates how to get the newly generated object after
            applying one of the generator ops with the ApplyGenOp command.
            It also demonstrates how to extract the newly applied operator
            object from the special ISIVTCollection which is a workaround for
            languages like JScript that don't support output arguments.
    */
    NewScene( null, false );
    // Use a Nurbs disc to apply the Fit Surface operator
    var original_3dobject = CreatePrim( "Disc", "NurbsSurface" );
    original_3dobject.innerradius.Value = 0.5;
    Application.LogMessage( original_3dobject.Name + " is a " + ClassName(original_3dobject) );
    // Get the ISIVTCollection back from this command. In this example, it contains
    // only one object (our operator), so we can just use this shortcut
    // NB: You cannot use siImmediateOperation for the ImmediateMode parameter if you
    //     want to get at the new object, because a frozen operator is invalid.
    var new_srffit_op = ApplyGenOp( "SrfFit", "NurbsSurface", original_3dobject,
            siUnspecified, siPersistentOperation, siKeepGenOpInputs, null)(0);
    Application.LogMessage( new_srffit_op.Name + " is a " + ClassName(new_srffit_op) );
    // You can change the operator's parameters to tweak the new surface mesh
    new_srffit_op.Parameters( "upoints" ).Value = 5;
    new_srffit_op.Parameters( "upoints" ).Value = 5;
    new_srffit_op.Parameters( "udeg" ).Value = 1;
    new_srffit_op.Parameters( "vdeg" ).Value = 1;
    // You can also get the newly generated object
    var newly_generated_object = new_srffit_op.OutputPorts(0).Target2.Parent;
    Application.LogMessage( newly_generated_object.Name + " is a " + ClassName(newly_generated_object) );
    // Output of above script:
    //INFO : disc is a X3DObject
    //INFO : Fit surface is a Operator
    //INFO : surfmsh is a X3DObject

#### 2. VBScript Example

    '
    '       This example demonstrates how to merge two mesh objects together and automatically delete the originals.
    '
    CreatePrim "Grid", "MeshSurface"
    Duplicate "grid", , 2, 1, 1, 0, 0, 1, 0, 1, , , , , , , , , , , 0
    Translate , 8.31067961165049, -8.32607541679225E-18, 0.135979621382887, siRelative, siView, siObj, siXYZ
    SelectObj "grid", , True
    AddToSelection "grid1", , True
    ApplyGenOp "MeshMerge", , , 3, siImmediateOperation, siDeleteGenOpInputs

#### 3. VBScript Example

    '
    '       This example demonstrates how to create surfaces from curves. It creates two polymsh objects and two
    '       srfmesh objects from the same input curves.
    '
    NewScene , false
    Dim oMeshRev, oMeshExt
    Dim oNurbsRev, oNurbsExt
    ' Create the two curves to use to create surfaces
    CreatePrim "Circle", "NurbsCurve"
    CreatePrim "Circle", "NurbsCurve"
    SetValue "circle1.circle.radius", 2
    Translate "circle1", 7, 0, 0, siAbsolute, siParent, siObj, siX
    ' Create NURBS surfaces of revolution and extrusion.
    ApplyGenOp "RevolutionAroundAxis", "NurbsSurface", "circle1", 3, siPersistentOperation, siKeepGenOpInputs, oNurbsRev
    Translate , 16, 0, 0, siAbsolute, siParent, siObj, siX
    Translate , 0, 8, 0, siAbsolute, siParent, siObj, siY
    ApplyGenOp "Extrusion", "NurbsSurface", "circle1;circle", 3, siPersistentOperation, siKeepGenOpInputs, oNurbsExt
    Translate , 16, 0, 0, siAbsolute, siParent, siObj, siX
    ' Create Mesh surfaces of revolution and extrusion.
    ApplyGenOp "RevolutionAroundAxis", "MeshSurface", "circle1", 3, siPersistentOperation, siKeepGenOpInputs, oMeshRev
    Translate , -12, 0, 0, siAbsolute, siParent, siObj, siX
    Translate , 0, 8, 0, siAbsolute, siParent, siObj, siY
    ApplyGenOp "Extrusion", "MeshSurface", "circle1;circle", 3, siPersistentOperation, siKeepGenOpInputs, oMeshExt
    Translate , -12, 0, 0, siAbsolute, siParent, siObj, siX
    ' Move a point on input circle to show the effect on all created surfaces from curve.
    Translate "circle1.pnt[12]", 0.0, 2, 0.0, siRelative, siView, siObj, siXYZ
    SetDisplayMode "Camera", "shaded"
    ' Select output and log information about created surfaces.
    SelectObj oMeshRev,,True
    AddToSelection oMeshExt,,True
    AddToSelection oNurbsRev,,True
    AddToSelection oNurbsExt,,True
    Application.LogMessage "Mesh Created from Revolution: " & oMeshRev
    Application.LogMessage "Mesh Created from Extrusion: " & oMeshExt
    Application.LogMessage "NURBS Created from Revolution: " & oNurbsRev
    Application.LogMessage "NURBS Created from Extrusion: " & oNurbsExt
    ' Running this script should log the following:
    ' ---------------------------------------------
    'INFO : "Mesh Created from Revolution: polymsh"
    'INFO : "Mesh Created from Extrusion: polymsh1"
    'INFO : "NURBS Created from Revolution: surfmsh"
    'INFO : "NURBS Created from Extrusion: surfmsh1"

### See Also

ApplyOperator ApplyOp ApplyTopoOp ApplyHairOp Generator and Converter Operators