RemoveLayer Method

Removes the layer with the specified index from the layer collection of the document. Returns the number of layers, remaining in the collection after the operation.

Applies to: Document object

Syntax

[[Let] countRet =] object.RemoveLayer ( index )

The RemoveLayer method syntax has these parts:

Part Description
object Required. An expression, that returns an instance of the Document object.
index

Required. An expression that returns a Long value. Indicates the index of the layer to be removed in the layer collection of the document.

countRet Optional. A Long type variable.

Remarks

If index is less than 1, or greater than the number of layers in the layer collection of the document, the RemoveLayer method doesn't remove the layer. When a layer is removed, the remaining layers are re-indexed - that is, the index of every layer after the removed one is decreased by 1.

You can't remove all the layers - at least one layer must exist in the document. An attempt to delete the last layer will have no effect.

Example

This example contains a document-level script. It removes all non-printable layers of the document by using the RemoveLayer method.

' Declare variables
Dim player As Layer

' Loop through all layers 
' starting from the end of the layer list of the current document
For i=thisDoc.LayersNum() To 1 Step -1

    ' Get next layer
    Set player = thisDoc.Layer(i)

    ' If layer is non-printable, remove the layer
    If player.Printable = False Then
        thisDoc.RemoveLayer(i)
    End If
Next i

 

See Also

AddLayer method, Layer method, LayerByID method, LayerByName method, LayersNum method, RemoveLayerByID method, Layer object