Searches for a layer with the specified name (the Name property) in the layer collection of the document. Returns an instance of the Layer object that corresponds to the first layer with the specified name, found in the layer collection.
Applies to: Document object
[[Set] layerRet =] object.LayerByName ( layerName ) |
The LayerByID method syntax has these parts:
Part | Description |
object | Required. An expression, that returns an instance of the Document object. |
layerName |
Required. An expression that returns a String value. Represents the name (the Name property) of the layer being searched. |
layerRet | Optional. A Layer type variable. |
If there is no layer with the specified name in the layer collection of the document, the LayerByName method returns Nothing.
This example contains a document-level script. The script shows how the LayerByName method is used to find the layer that was created earlier (with less index) among two layers with the same names.
' Declare variables Dim layer1 As Layer Dim layer2 As Layer Dim reslayer As Layer ' Add two new layers to the document Set layer1 = thisDoc.AddLayer() Set layer2 = thisDoc.AddLayer() ' Give the same name to both layers layer1.Name = "Layer Name" layer2.Name = "Layer Name" ' Display the names to make sure they are the same. TRACE layer1.Name TRACE layer2.Name ' Search for layer with specified name Set reslayer = thisDoc.LayerByName( "Layer Name" ) ' Display the references to the instances of the Layer object, ' to make sure that the LayerByName method ' returned the reference to the first added layer - layer1 TRACE "layer1 = " & layer1 TRACE "layer2 = " & layer2 TRACE "reslayer = " & reslayer ' Delete layers thisDoc.RemoveLayerByID( layer1.ID ) thisDoc.RemoveLayerByID( layer2.ID ) |
See Also |
AddLayer method, Layer method, LayerByID method, LayersNum method, RemoveLayer method, RemoveLayerByID method, Layer object |