1

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?)

3
  • The error is 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. – Erica Mar 6 '15 at 13:51
  • Yes that does work. But I wanted to use the bookmark name (bkmk.name) to add to the output name. Any suggestion for accessing the bookmark name in another way? – Fynnster Mar 6 '15 at 13:55
  • 1
    I'll give you a full Answer, it'll be easier to read ;) – Erica Mar 6 '15 at 13:56
3

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
1
  • 1
    Thank 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 Mar 6 '15 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.