AnsweredAssumed Answered

Arcpy Batch ExportToJPEG & OverwriteOutput Not Working

Question asked by JCrouch_ResponseGroup on Apr 26, 2017
Latest reply on Apr 27, 2017 by JCrouch_ResponseGroup

Hello All,

 

I am working on a script to batch export a list of user selected MXD's to either JPEG, PDF, or JPEG & PDF using arcpy.mapping.exportToJPEG. I give the user the option to overwrite existing images in the selected output location however the JPEG's will not overwrite while the PDF's will. 

 

Does anyone know why this might happen? I have researched it a bit and am unable to find a solution.

 

import arcpy as ap
import os

docs = ap.GetParameterAsText(0)
exportPath = ap.GetParameterAsText(1)
imgRes = ap.GetParameterAsText(2)
imgJPEG = ap.GetParameterAsText(3)     #Boolean
imgPDF = ap.GetParameterAsText(4)     #Boolean
overwrite = ap.GetParameterAsText(5)     #Boolean

def transmit(message):
     ap.AddMessage(message)
     return

def exportGraphics(docs, exportPath, imgRes, imgJPEG, imgPDF, overwrite):
     
     if str(overwrite) == 'true':
          ap.env.overwriteOutput = True

     for doc in docs.split(';'):
          mxdname = os.path.basename(doc)
          mxdname = mxdname.split('.mxd')[0]

          mxd = ap.mapping.MapDocument(doc)

          if str(imgJPEG) == 'true':
               jpg = os.path.join(exportPath,mxdname) + '.jpg'
               ap.mapping.ExportToJPEG(mxd, jpg, resolution = imgRes)
               transmit(mxdname + '.jpg Has Exported!')
          if str(imgPDF) == 'true':
               pdf = os.path.join(exportPath,mxdname) + '.pdf'
               ap.mapping.ExportToPDF(mxd,pdf, resolution = imgRes)
               transmit(mxdname + '.pdf Has Exported!')

          del mxd



if __name__ == '__main__':

     exportGraphics(docs, exportPath, imgRes, imgJPEG, imgPDF, overwrite)

 

Thanks in advance!

 

Judson

Outcomes