Thursday, 1 September 2016

Exporting mxds into pdfs using ArcPy?



I have written a python script to export my mxd into a pdf (not using data driven pages). I am getting the error that my mxd path is incorrect! I have included my script below. Any help would be appreciated.


# Necessary modules
import arcpy, os, string, sys

# For less complicated scripts -
# these 2 imports are necessary to utilize a simpler method of debugging outher than traceback
import win32ui, win32con

# example debug message to screen ......
# arcpy.AddMessage("mxd_file = " + str(mxd_file))

# val = win32ui.MessageBox("mxd_file = " + str(mxd_file), "title",
#win32con.MB_OKCANCEL)

#Paramaters...

mxdList = string.split(arcpy.GetParameterAsText(0), ";")
dir = arcpy.GetParameterAsText(1)

#Loop thru & take the base name of each MXD selected and append all map pages to a single pdf
# and save to chosen directory......


for mxdPath in mxdList:
mxd = arcpy.mapping.MapDocument(mxdPath)
name = mxdPath[:-4] + ".pdf"
file = dir + os.sep + os.path.basename(name)
ddp = mxd
ddp.exportToPDF(file, "ALL")

del mxd, file


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...