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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Mar 6, 2015 at 13:47
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. Commented Mar 6, 2015 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? Commented Mar 6, 2015 at 13:55
  • 1
    I'll give you a full Answer, it'll be easier to read ;) Commented Mar 6, 2015 at 13:56

1 Answer 1

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
answered Mar 6, 2015 at 13:58
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!! Commented Mar 6, 2015 at 14:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.