ArcObjects Library Reference  (Carto)    

IMap.Layers Property

The layers in the map of the type specified in the uid. If recursive is true it will return layers in group layers.

[Visual Basic 6.0]
Property Layers(
    [ByVal uid As IUID], _
    [ByVal recursive As Boolean] _
) As IEnumLayer
[Visual Basic .NET]
Public Function get_Layers ( _
    [ByVal uid As UID], _
    [ByVal recursive As Boolean] _
) As IEnumLayer
public IEnumLayer get_Layers (
    UID uid,
    bool recursive

Optional Values

uid   Supply 0 as a default value.
recursive   Supply true as a default value.
public  getLayers (
    IUID uid,
    boolean recursive,
    IEnumLayer Layers
HRESULT get_Layers(
  IUID* uid,
  VARIANT_BOOL recursive,
  IEnumLayer** Layers


uid [in, optional, defaultvalue(0)]

  uid is a parameter of type IUID

recursive [in, optional, defaultvalue(VARIANT_TRUE)]

  recursive is a parameter of type VARIANT_BOOL

Layers [out, retval]

  Layers is a parameter of type IEnumLayer

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.


UID specifies the interface identifier (GUID) that represents the type of layer you want returned.

recursive Use True to also return the layers inside group layers.

See the sample code associated with the FeatureSelection property for an example of use.


The Layers property returns an IEnumLayer which consists of only those layers with the type specified by the input interface unique indentifier. The Layer property provides access to all of the Layers in a map; using the Layers property however, you can access just the layers of a particular type. For example, use this property to get a collection of FeatureLayers only. To create this collection use IGeoFeatureLayer's GUID as the FeatureLayer object is the only type of layer that implements this interface. Similarly, to get just a collection of the graphics layers, pass the IGraphicsLayer's GUID. Use IDataLayer if you want all the layers that have data in them, this would not include GroupLayers for example. Layers that implement IDataLayer include FeatureLayers, FDOGraphicsLayers (Annotation), TinLayer, RasterLayer, and CoverageAnnotationLayer.
Here are the GUIDs for some of the common intefaces searched for:
{6CA416B1-E160-11D2-9F4E-00C04F6BC78E} IDataLayer
{40A9E885-5533-11d0-98BE-00805F7CED21} IFeatureLayer
{E156D7E5-22AF-11D3-9F99-00C04F6BC78E} IGeoFeatureLayer
{34B2EF81-F4AC-11D1-A245-080009B6F22B} IGraphicsLayer
{5CEAE408-4C0A-437F-9DB3-054D83919850} IFDOGraphicsLayer
{0C22A4C7-DAFD-11D2-9F46-00C04F6BC78E} ICoverageAnnotationLayer
{EDAD6644-1810-11D1-86AE-0000F8751720} IGroupLayer
[Visual Basic 6.0]
Below is a very simple VBA subroutine that demonstates this property.
Sub GetFeatureLayers()
  Dim pMxDocument As IMxDocument
  Dim pMap As IMap
  Dim pEnumLayer As IEnumLayer
  Dim pLayer As ILayer
  Dim pId As New UID

  Set pMxDocument = Application.Document
  Set pMap = pMxDocument.FocusMap
  pId = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"
  Set pEnumLayer = pMap.Layers(pId, True)
  Set pLayer = pEnumLayer.Next
  Do While Not pLayer Is Nothing
    MsgBox pLayer.Name
    Set pLayer = pEnumLayer.Next
End Sub

See Also

IMap Interface