kh0annguyen

Batch export script: invalid mxd filename

Discussion created by kh0annguyen on May 30, 2012
Latest reply on May 30, 2012 by kh0annguyen
I run this as a standalone script without error all the time. But when I execute it in ArcToolbox I get an "Invalid mxd filename" error. Seems like an easy fix but I've never made a tool before... here's the code

import arcpy.mapping, os

inPath = arcpy.GetParameterAsText(0)
outPath = arcpy.GetParameterAsText(1)
res = arcpy.GetParameterAsText(2)
format = arcpy.GetParameterAsText(3)

# inPath = 'c:/Project/'
# outPath = 'c:/Project/Output/'
# res = 96
# format = 'pdf'

if not os.path.isdir(outPath):
 os.mkdir(outPath)
for root, dirs, files in os.walk(inPath):
 for file in files:
  if '.mxd' in file:
   mxd = arcpy.mapping.MapDocument(inPath + file)
   (filename, extension) = os.path.splitext (file)
   if format   == 'jpg' or format == 'jpeg':
    arcpy.mapping.ExportToJPEG(mxd, outPath + filename + '.jpg', resolution = res)
   elif format == 'png':
    arcpy.mapping.ExportToPNG (mxd, outPath + filename + '.png', resolution = res)
   elif format == 'bmp':
    arcpy.mapping.ExportToBMP (mxd, outPath + filename + '.bmp', resolution = res)
   elif format == 'pdf':
    arcpy.mapping.ExportToPDF (mxd, outPath + filename + '.pdf', resolution = res)

Outcomes