Select to view content in your preferred language

Batch export script: invalid mxd filename

1254
4
05-30-2012 09:37 AM
PeterNguyen
Deactivated User
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)
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Honored Contributor
I'd try modifying your mxd setting line to this.
mxd = arcpy.mapping.MapDocument(os.path.join(inPath,file))
0 Kudos
PeterNguyen
Deactivated User
Thanks for the reply. Script completes with no error now but there's no output (completes in 0.0 seconds)
0 Kudos
MathewCoyle
Honored Contributor
You should try adding some messages in to see what is happening. For example, you have no else case that would catch if your export format is valid.

Eg. 'PDF' != 'pdf'
0 Kudos
PeterNguyen
Deactivated User
Alrighty, I will play around with it some more. I was also thinking it might be the way I configured the parameters in the ArcToolbox properties.
0 Kudos