## TextureLayer.AddTextureLayerPort

### Introduced

v4.0

### Description

Adds a TextureLayerPort object (shader connection) to a texture layer. These indicate what shader ports are being driven by the layer.
If the layer has ports added to it on containers it currently does not belong to, it will be added to these containers (at the correct place in the stack, maintaining layer order dependencies). For example, suppose a render tree has both Phong and Lambert shaders, and the Phong already has a layer "Dirt", but this layer is not shared with Lambert. If we call TextureLayer.AddTextureLayerPort to the target "Lambert.diffuse", then layer "Dirt" will be added to the list of layers under Lambert, even though we did not explicitly call Shader.AddSharedTextureLayer on that shader.

### C# Syntax

    TextureLayerPort TextureLayer.AddTextureLayerPort( Object in_varParam );

### Scripting Syntax

    oReturn = TextureLayer.AddTextureLayerPort( Target );

### Return Value

TextureLayerPort

### Parameters

Parameter | Type | Description
--- | --- | ---
Target | Parameter or String | Parameter on the target (must be a port on a shader or material) to which to add a texture layer port connection (that is, to be driven by this layer). Note that if a target is specified on a (valid) container which currently does not nest the layer, the layer will be added to that container.

### Examples

#### 1. JScript Example

    // This example shows creation of texture layer
    // ports, plus enumerating them.
    oRoot = ActiveProject.ActiveScene.Root;
    oSph = oRoot.AddGeometry( "Sphere", "MeshSurface" );
    oMat = oSph.AddMaterial( "Phong" );
    oPhong = oMat.Shaders(0);
    oParam = oPhong.parameters( "specular" );
    oFractal = oParam.ConnectFromPreset( "Fractal", siTextureShaderFamily );
    // Add a layer at the end.
    oLayer = oPhong.CreateTextureLayer( "DirtLayer" );
    // Add some texture layer port connections on this layer.
    oPorts = new Array(3);
    oPorts[0] = oLayer.AddTextureLayerPort( oPhong.parameters( "ambient" ) );
    oPorts[1] = oLayer.AddTextureLayerPort( oPhong.parameters( "diffuse" ) );
    // The next line shows adding a port which is on a container that the layer
    // is currently not part of -- it will be added to that container.
    oPorts[2] = oLayer.AddTextureLayerPort( oFractal.parameters( "color1" ) );
    Application.LogMessage( "Created " + oLayer.TextureLayerPorts.count + " ports." );
    for ( i = 0; i < oLayer.TextureLayerPorts.count; i++ )
    {
            oPort = oLayer.TextureLayerPorts(i);
            Application.LogMessage( (i+1) + ": " + oPort );
    }
    // This example should log something like:
    //INFO : "Created 3 ports."
    //INFO : "1: sphere.Material.Phong.DirtLayer.ambient"
    //INFO : "2: sphere.Material.Phong.DirtLayer.diffuse"
    //INFO : "3: sphere.Material.Phong.DirtLayer.color1"

#### 2. VBScript Example

    ' This example shows creation of texture layer
    ' ports, plus enumerating them.
    set oRoot = ActiveProject.ActiveScene.Root
    set oSph = oRoot.AddGeometry( "Sphere", "MeshSurface" )
    set oMat = oSph.AddMaterial( "Phong" )
    set oPhong = oMat.Shaders(0)
    set oParam = oPhong.parameters( "specular" )
    set oFractal = oParam.ConnectFromPreset( "Fractal", siTextureShaderFamily )
    ' Add a layer at the end.
    set oLayer = oPhong.CreateTextureLayer( "DirtLayer" )
    ' Add some texture layer port connections on this layer.
    dim oPorts(2)
    set oPorts(0) = oLayer.AddTextureLayerPort( oPhong.parameters( "ambient" ) )
    set oPorts(1) = oLayer.AddTextureLayerPort( oPhong.parameters( "diffuse" ) )
    ' The next line shows adding a port which is on a container that the layer
    ' is currently not part of -- it will be added to that container.
    set oPorts(2) = oLayer.AddTextureLayerPort( oFractal.parameters( "color1" ) )
    logmessage "Created " & oLayer.TextureLayerPorts.count & " ports."
    i = 1
    for each oPort in oLayer.TextureLayerPorts
            logmessage i & ": " & oPort
            i = i + 1
    next
    ' This example should log something like:
    'INFO : "Created 3 ports."
    'INFO : "1: sphere.Material.Phong.DirtLayer.ambient"
    'INFO : "2: sphere.Material.Phong.DirtLayer.diffuse"
    'INFO : "3: sphere.Material.Phong.DirtLayer.color1"

### See Also

AddTextureLayerPorts TextureLayer.TextureLayerPorts TextureLayer.RemoveTextureLayerPort