When I try to run the following simple script from arcmap it fails but when run using right--click debug and then F9 (debug) in python scripter it works fine. I don't understand why???
# Modified by: Georgec Corea (ATGIS) [email protected]
# Author: ESRI
# Date: July 5, 2010
# Version: ArcGIS 10.0
# Purpose: This script will print one or more map documents to a local printer.
# The script is intended to run within a script tool. There are two
# parameters:
# 1) Select Map Documents to Print,
# 2) Select Output Printer (auto populated using a validation script)
#
#Notes: The print order of the MXDs is based on how they are entered. The MXD
# at the top of the list is first followed by those below it.
import arcpy, string, datetime, shutil, os
import arcpy.mapping as MAP
#Read input parameters from script tool
MXDList = string.split(arcpy.GetParameterAsText(0), ";")
#printer = arcpy.GetParameterAsText(1)
count=0
#Loop through each MXD and print
for MXDPath in MXDList:
count=count+1
arcpy.AddMessage(str(count)+'. Working on '+str(MXDPath)+' @ '+str(datetime.datetime.now())+"\n")
## try:
mxd=arcpy.mapping.MapDocument(MXDPath)
outPDFpath = mxd.filePath[:mxd.filePath.rfind('.')]+'.pdf'
ddp = mxd.dataDrivenPages
#MXD = MAP.MapDocument(mxd)
#arcpy.AddMessage(ddp, MXD)
if str(os.path.isfile(outPDFpath))=='False':
outputPDF = arcpy.mapping.PDFDocumentCreate(outPDFpath)
mxd.dataDrivenPages.exportToPDF(outPDFpath)
#arcpy.mapping.ExportToPDF(mxd, outPDFpath)
name='c:\\temp\\'+outPDFpath[outPDFpath.rfind('\\'):]
shutil.copy2(outPDFpath,name)
arcpy.AddMessage('Printed '+str(outPDFpath)+' @ '+str(datetime.datetime.now())+"\n")
else:
arcpy.AddMessage('File Exists '+str(outPDFpath)+' skipped pdf creation @ '+str(datetime.datetime.now())+"\n")
## except:
## errorm=arcpy.GetMessages()
## arcpy.AddMessage(' Error creating file...' +str(outPDFpath)+'\n'+str(errorm)+'\n'+' continuing...')
#MAP.PrintMap(MXD, printer)
#Remove variable reference to file
del mxd
When run in debug