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


Create Spatial Bookmark for ActiveView Extent Snippet (ArcObjects .NET 10.6 SDK)
ArcObjects Library Reference

Create Spatial Bookmark for ActiveView Extent Snippet

Using the IActiveView's current extent create a spatial bookmark.

[C#]
///<summary>Using the IActiveView's current extent create a spatial bookmark.</summary>
/// 
///<param name="activeView">An IActiveView interface</param>
///<param name="bookmarkName">A System.String that is the name of what you want to call the bookmark. Example: "USA"</param>
///  
///<remarks></remarks>
public void CreateSpatialBookmarkForActiveViewExtent(ESRI.ArcGIS.Carto.IActiveView activeView, System.String bookmarkName)
{
  if(activeView == null || bookmarkName == null)
  {
    return;
  }
  // Create a new bookmark and set it's location to the focus map's current extent
  ESRI.ArcGIS.Carto.IAOIBookmark aoiBookmark=new ESRI.ArcGIS.Carto.AOIBookmarkClass();

  // Bookmark set for the current extent
  aoiBookmark.Location=activeView.Extent;
  aoiBookmark.Name=bookmarkName;

  // Add the bookmark to the map's bookmark collection  
  // For ArcGIS Desktop this will add the bookmark to the View | Bookmarks menu 
  ESRI.ArcGIS.Carto.IMapBookmarks mapBookmarks=activeView as ESRI.ArcGIS.Carto.IMapBookmarks; // Dynamic Cast
  mapBookmarks.AddBookmark(aoiBookmark);
}
[Visual Basic .NET]
'''<summary>Using the IActiveView's current extent create a spatial bookmark.</summary>
''' 
'''<param name="activeView">An IActiveView interface</param>
'''<param name="bookmarkName">A System.String that is the name of what you want to call the bookmark. Example: "USA"</param>
'''  
'''<remarks></remarks>
Public Sub CreateSpatialBookmarkForActiveViewExtent(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal bookmarkName As System.String)

  If activeView Is Nothing OrElse bookmarkName Is Nothing Then
        Return
  End If

  ' Create a new bookmark and set it's location to the focus map's current extent
  Dim aoiBookmark As ESRI.ArcGIS.Carto.IAOIBookmark=New ESRI.ArcGIS.Carto.AOIBookmarkClass

  ' Bookmark set for the current extent
  aoiBookmark.Location=activeView.Extent
  aoiBookmark.Name=bookmarkName

  ' Add the bookmark to the map's bookmark collection  
  ' For ArcGIS Desktop this will add the bookmark to the View | Bookmarks menu 
  Dim mapBookmarks As ESRI.ArcGIS.Carto.IMapBookmarks=TryCast(activeView, ESRI.ArcGIS.Carto.IMapBookmarks) ' Dynamic Cast
  mapBookmarks.AddBookmark(aoiBookmark)

End Sub

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