I want to use the bookmarks in ArcMap 10.2.2 and 10.3 MXDs to loop through the bookmarks, zoom to the extent of said bookmark and then export a PDF by renaming the PDF with the name of the bookmark. It seems like a simple task especially when Esri offers a greate example for this (from http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000060000000)
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Users\Kim\Documents\Work_related\NursingSchool\P20_OnlineWellStudy\PBH_interpolationSurfaces.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Dataframe")[0]
for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):
print bkmk
df.extent = bkmk.extent
outFile = r"C:\Users\Kim\Documents\Work_related\NursingSchool\P20_OnlineWellStudy\PBH_interpolationSurfaces\\" + bkmk.name + ".pdf"
arcpy.mapping.ExportToPDF(mxd, outFile, df)
del mxd
BUT, I've run this code and variances of it, with the same error:
Runtime error
Traceback (most recent call last):
File "<string>", line 8, in <module>
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\mapping.py", line 1139, in ExportToPDF
layout.exportToPDF(*args)
AttributeError: Invalid destination path
What does this error mean? I don't know what I need to change in the parsing error for the ExportToJPEC. I've changed this to ExportToPDF and get the same error. I thought it might be triggered from the bookmark "printBookmark" being inaccessible, but I can access that by simple using a print statement:
Bookmark(name=u'printBookmark', extent=<Extent object at 0x23227670[0x22c36ad0]>).
Is this related to the difference between ArcGIS versions (10.1. vs. 10.2.2?)
1 Answer 1
Since your error is Invalid destination path
, the script doesn't like the output file name (presumably the two slashes at the end).
There are a few different ways to put that output name together. I'd personally do something like:
import arcpy
import os
mxd = arcpy.mapping.MapDocument(r"C:\Users\Kim\Documents\Work_related\NursingSchool\P20_OnlineWellStudy\PBH_interpolationSurfaces.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Dataframe")[0]
outDir = r"C:\Users\...\PBH_interpolationSurfaces" ### note, no \ at the end
for bkmk in arcpy.mapping.ListBookmarks(mxd, data_frame=df):
print bkmk
df.extent = bkmk.extent
outFile = os.path.join(outDir, "{}.pdf".format(bkmk.name))
arcpy.mapping.ExportToPDF(mxd, outFile, df)
del mxd
-
1Thank you so much for your answer! I have some fixes to make with my layers, but this will be a great solution when data-driven pages are harder to use (for the other GIS users). Your expertise is much appreciated!!Fynnster– Fynnster2015年03月06日 14:10:51 +00:00Commented Mar 6, 2015 at 14:10
Invalid destination path
-- check your script with a single PDF (e.g.outFile = r"C:\temp\out.pdf"
), does that work? If so, you'll need to adjust how you create that variable.