Searches for a layer with the specified ID (ID property) in the layer collection of the document. Returns an instance of the Layer object that corresponds to the found layer.
Applies to: Document object
[[Set] layerRet =] object.LayerByID ( layerID ) |
The LayerByID method syntax has these parts:
Part | Description |
object | Required. An expression, that returns an instance of the Document object. |
layerID | Required. An expression that returns a Long value. Represents the ID (ID property) of the layer being searched. |
layerRet | Optional. A Layer type variable. |
If there is no layer with the specified ID (ID property) in the layer collection of the document, the LayerByID method returns Nothing.
This example contains a document-level script. The LayerByID method uses the layer ID taken from a shape on that layer.
' Declare variables Dim shp1 As Shape Dim shp2 As Shape Dim layerID As Long Dim player As Layer ' Set the first layer from the layer collection as active layer thisDoc.ActiveLayer = thisDoc.Layer(1).ID ' Draw a rectangle on the active layer Set shp1 = thisDoc.ActivePage.DrawRect(100,100,600,500) shp1.Text = "Layer # 1" ' Use the LayerByID method to get the layer on which the shp1 shape ' was created Set player = thisDoc.LayerByID( shp1.Layer ) ' Set blue color for all shapes on the layer player.Colored = True player.Color.SetRGB( 0,0,255 ) ' Make the second layer from the layer collection ' active layer thisDoc.ActiveLayer = thisDoc.Layer(2).ID ' Draw a rectangle on the active layer Set shp2 = thisDoc.ActivePage.DrawRect(700,100,1200,500) shp2.Text = "Layer # 2" ' Use the LayerByID method to get the layer on which the shp2 shape ' was created Set player = thisDoc.LayerByID( shp2.Layer ) ' ' Set red color for all shapes on the layer player.Colored = True player.Color.SetRGB( 255,0,0 ) |
See Also |
ID property, AddLayer method, Layer method, LayerByName method, LayersNum method, RemoveLayer method, RemoveLayerByID method, Layer object |