This document is archived and information here might be outdated.  Recommended version.

How to access maps and layers via the MxDocument (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Working with map documents > How to access maps and layers via the MxDocument

How to access maps and layers via the MxDocument

MxDocument is the class representing the map document in ArcMap. This makes the class a central point to ArcMap customization. This topic demonstrates how to access the maps and layers of a map document via IMxDocument.

Accessing maps and layers via the MxDocument

In the following code example, the maps and layers are looped through and the names of these objects are reported to the console. Do the following steps to access maps and layers:
  1. Get the maps from the MxDocument.
IMap pMap;
IMaps pMaps=pMxDocument.Maps;
Dim pMap As IMap
Dim pMaps As IMaps=pMxDocument.Maps
  1. Enumerate through the maps and output the name of each map to the console. See the following code example:
for (int i=0; i <= pMaps.Count - 1; i++)
    IEnumLayer pEnumLayer=pMap.get_Layers(null, true);
    ILayer pLayer=pEnumLayer.Next();
    while (pLayer != null)
Dim i As Integer
For i=0 To pMaps.Count - 1 Step i + 1
    Dim pEnumLayer As IEnumLayer=pMap.Layers(Nothing, True)
    Dim pLayer As ILayer=pEnumLayer.Next()
    While Not pLayer Is Nothing
    End While

Additional Requirements
  • pMxDocument - An IMxDocument referencing the map document that you want to access.

Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced