Is it possible to export the extents of all bookmarks in an active map document to a shape file containing the polygons of the shape and/or to automate the print to pdf of all the bookmark extents.
The code for doing this with extents is below but I want to do the same with bookmarks.
[code] > import arcpy, glob, os, sys from arcpy import env from arcpy import mapping from datetime import datetime from time import strftime
env.overwriteOutput = True
path = os.getcwd() # Script in same directory as files being processed path2 = path + r'\temp_extents' mxdList = glob.glob(path + "*.mxd") #env.workspace = path + '\extents' # Directory as files being processed
print 'Reading mxd files from ' + path #os.remove(path2 + r'*.*') #os.rmdir(path2) os.mkdir(path2) env.workspace = path2 print 'Working in ' + env.workspace
x = 0 y = 1 z = 1
while y < 7:
for mxd in mxdList:
mxd2 = mapping.MapDocument(mxd)
print 'Processing ' + mxd
try:
dataframe = mapping.ListDataFrames(mxd2, "*")[x]
frameExtent = dataframe.extent
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
polygon = arcpy.Polygon(array)
#Create Polygon Shapefile
arcpy.CreateFeatureclass_management(path2, "Polygon_Extent" + "_" + str(z), "POLYGON")
arcpy.CopyFeatures_management(polygon, "Polygon_Extent" + "_" + str(z))
#print 'Created...' "Polygon_Extent" + "_" + str(z)
mapDoc = "Polygon_Extent" + "_" + str(z) + ".shp"
print 'Created ...' + mapDoc
#Capture and Enter ExtentID, File Name and other info for el in arcpy.mapping.ListLayoutElements(mxd2, "DATAFRAME_ELEMENT"): ExtentIDStore = el.name #list2.append = ExtentIDStore #list2.append(ExtentIDStore) print ExtentIDStore #print ExtentIDStore[1] #print list2[y]
dfStore = path2 + "\Polygon_Extent" + "_" + str(z) + ".shp"
#open (dfStore, 'w')
arcpy.AddField_management(dfStore,'ExtentID','TEXT') #should only be done once per shp
arcpy.AddField_management(dfStore,'FileRef','TEXT') #should only be done once per shp
arcpy.AddField_management(dfStore,'Scale','SHORT') #should only be done once per shp
#print arcpy.GetMessages()
# code to add ExtentID,mxd and scale value to shp file
#rows = arcpy.InsertCursor()
#print 'Filling in ', rows
#row = rows.newRow()
#row.PATH = mapDoc.filePath
#row.TITLE = mapDoc.title
#row.AUTHOR = mapDoc.author
#row.LASTSAVED = mapDoc.dateSaved
#row.LASTUPDATE = datetime.strftime(datetime.now(),"%Y-%m-%d")
#row.strField = str(x)
#rows.insertRow(row)
#print arcpy.GetMessages()
# code to add mxd
#TFileRef = mxd
#FileRef = TFileRef
#print arcpy.GetMessages()
#rows = arcpy.InsertCursor(FileRef)# FileRef here refers to the column called FileRef created above
#row = rows.newRow()
#row.FileRef = TFileRef
#rows.insertRow(row) #save row
#del row #unlock row
#del rows #unlock table
#END - Capture and Enter ExtentID, File Name and other info
z = z + 1
except IndexError:
pass
x = x + 1
y = y + 1
list = []
lstFCs = arcpy.ListFeatureClasses("Polygon_Extent*") print 'Merging Polygon_Extents* to Extent.shp'
for fc in lstFCs: list.append(fc)
arcpy.Merge_management(list, "Extent") print 'Deleting identical entries' arcpy.DeleteIdentical_management("Extent.shp", ["SHAPE"]) print 'Created Extent.shp and exiting'
#for item in list: #arcpy.Delete_management(item)
[/code]