Get Map from ArcMap Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Get Map from ArcMap Snippet

Get Map from ArcMap.

[C#]
///<summary>Get Map from ArcMap</summary>
///  
///<param name="application">An IApplication interface that is the ArcMap application.</param>
///   
///<returns>An IMap interface.</returns>
///   
///<remarks></remarks>
public ESRI.ArcGIS.Carto.IMap GetMapFromArcMap(ESRI.ArcGIS.Framework.IApplication application)
{
  if (application == null)
  {
    return null;
  }
  ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument=((ESRI.ArcGIS.ArcMapUI.IMxDocument)(application.Document)); // Explicit Cast
  ESRI.ArcGIS.Carto.IActiveView activeView=mxDocument.ActiveView;
  ESRI.ArcGIS.Carto.IMap map=activeView.FocusMap;

  return map;
  
}
[Visual Basic .NET]
'''<summary>Get Map from ArcMap</summary>
'''  
'''<param name="application">An IApplication interface that is the ArcMap application.</param>
'''   
'''<returns>An IMap interface.</returns>
'''   
'''<remarks></remarks>
Public Function GetMapFromArcMap(ByVal application As ESRI.ArcGIS.Framework.IApplication) As ESRI.ArcGIS.Carto.IMap

  Dim mxDocument As ESRI.ArcGIS.ArcMapUI.IMxDocument=CType(application.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument) ' Explicit Cast
  Dim activeView As ESRI.ArcGIS.Carto.IActiveView=mxDocument.ActiveView
  Dim map As ESRI.ArcGIS.Carto.IMap=activeView.FocusMap

  Return map

End Function

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.ArcMapUI
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System