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:
- Get the maps from the MxDocument.
IMap pMap;
IMaps pMaps = pMxDocument.Maps;
[VB.NET]
Dim pMap As IMap
Dim pMaps As IMaps = pMxDocument.Maps
- 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++)
{
pMap = pMaps.get_Item(i);
Console.WriteLine(pMap.Name);
IEnumLayer pEnumLayer = pMap.get_Layers(null, true);
pEnumLayer.Reset();
ILayer pLayer = pEnumLayer.Next();
while (pLayer != null)
{
Console.WriteLine(pLayer.Name);
pLayer = pEnumLayer.Next();
}
}
[VB.NET]
Dim i As Integer
For i = 0 To pMaps.Count - 1 Step i + 1
pMap = pMaps.Item(i)
Console.WriteLine(pMap.Name)
Dim pEnumLayer As IEnumLayer = pMap.Layers(Nothing, True)
pEnumLayer.Reset()
Dim pLayer As ILayer = pEnumLayer.Next()
While Not pLayer Is Nothing
Console.WriteLine(pLayer.Name)
pLayer = pEnumLayer.Next()
End While
Next
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |