Accessing a Map Documents Bookmarks through Python and ArcPy

5235
12
07-12-2010 03:33 PM
JayDouillard
New Contributor II
Is there a way to access the bookmarks within a map document with arcpy? I have a mxd that has several bookmarks, and I'd like to write a script that zooms to the extent of each bookmark, and exports a pdf.
0 Kudos
12 Replies
JeffBarrette
Esri Regular Contributor
You can build the polygons from the bookmark extents using the Polygon class.  Check out the following help topic/sample:
http://resources.arcgis.com/en/help/main/10.1/#/Polygon/018z00000061000000/

Also, check out the 4th example in the arcpy.mapping DataFrame class help.  This also creates a polygon feature.
http://resources.arcgis.com/en/help/main/10.1/#/DataFrame/00s300000003000000/

Jeff
0 Kudos
JeffMoulds
Esri Contributor
Annelies,

Great idea for a sample, and good timing...I just wrote a script that will do this:

import arcpy, os

# The map with the bookmarks
mxd = arcpy.mapping.MapDocument(r"C:\Project\BookmarksToFeatures.mxd")

# The output feature class to be created -
# This feature class will store the bookmarks as features
outFC = r'C:\Project\BookmarkFeatures.gdb\Bookmarks'

# A template feature class that contains the attribute schema
# E.g. a "name" field to store the bookmark name
template = r'C:\Project\BookmarkFeatures.gdb\Template'

if arcpy.Exists(outFC):
    arcpy.Delete_management(outFC)
arcpy.CreateFeatureclass_management(os.path.dirname(outFC),
                                    os.path.basename(outFC), 
                                    "POLYGON", template, 
                                    spatial_reference=template)

cur = arcpy.da.InsertCursor(outFC, ["SHAPE@", "Name"])
array = arcpy.Array()
for bkmk in arcpy.mapping.ListBookmarks(mxd):
    array.add(arcpy.Point(bkmk.extent.XMin, bkmk.extent.YMin))
    array.add(arcpy.Point(bkmk.extent.XMin, bkmk.extent.YMax))
    array.add(arcpy.Point(bkmk.extent.XMax, bkmk.extent.YMax))
    array.add(arcpy.Point(bkmk.extent.XMax, bkmk.extent.YMin))
    # To close the polygon, add the first point again
    array.add(arcpy.Point(bkmk.extent.XMin, bkmk.extent.YMin))
    cur.insertRow([arcpy.Polygon(array), bkmk.name])
    array.removeAll()
0 Kudos
CPoynter
Occasional Contributor III
Hi Jeff,

Would it be possible to modify your bookmarks script to reference individual FC tiles to make up a reference type index using a similar process?

Regards,

Craig
0 Kudos