Batch Export a directory to PDFs and Data Driven Pages?

641
0
04-09-2019 09:05 AM
ShelbyZemken1
New Contributor III

I've written a script to export all mxds in a directory to PDFs. The issue I'm running into is that some of those MXDs have data driven pages enabled, so they export only the first page. As far as I can tell I need to create a list of MXDs that have data driven pages enabled and then loop over that list and export. I get the following error when I run the code below:

Traceback (most recent call last):
File "C:\Users\XXXX\Documents\ArcGIS\TBX.tbx#BatchExportToPDF.py", line 14, in <module>
TypeError: ListFiles() got an unexpected keyword argument 'isddpEnabled'

How can I generate a list of mxds with ddp enabled, and a list of mxds without it enabled, and then loop through both of them and get all my MXDs exported ?

#Script takes all .mxd files in a user defined directory and
#exports them to the user defined directory

#imports relevant modules
import os, arcpy

#user sets input and output directories
input_dir = arcpy.GetParameterAsText(0)
output_dir = arcpy.GetParameterAsText(1)

arcpy.env.workspace = ws = str(input_dir)

#need to loop through mxd_list and grab docs where variablename.ddpenabled. if true the put in list
mxd_list = arcpy.ListFiles("*.mxd",isddpEnabled = False)
ddp_list = arcpy.ListFiles("*.mxd'",isddpEnabled = True)

for mxd in mxd_list:
    #creates variable that opens an arcmap document at input dir + .mxd
    current_mxd = arcpy.mapping.MapDocument(os.path.join(ws, mxd))
    #creates variable that stores output directory + mxd
    pdf_name = (os.path.join(output_dir, mxd[:-4]) + ".pdf")
    #exports the mxd to the output folder
    arcpy.mapping.ExportToPDF(current_mxd, pdf_name)
    arcpy.AddMessage('\t' + mxd + str(' exported successfully.'))
del mxd_list

for mxd in ddp_list:
    #creates variable that opens an arcmap document at input dir + .mxd
    current_mxd = arcpy.mapping.MapDocument(os.path.join(ws, mxd))
    #creates variable that stores output directory + mxd
    pdf_name = (os.path.join(output_dir, mxd[:-4]) + ".pdf")
    #exports the ddp mxd to the output folder
    ddp = current_mxd.dataDrivenPages
    ddp.datadrivenpages(pdf_name, "ALL")
    arcpy.AddMessage('\t' + mxd + str(' exported successfully.'))
del mxd_list

arcpy.AddMessage(('Exports complete!'))

complete = os.startfile(output_dir)
complete
0 Kudos
0 Replies