Errno: 10054 when batch exporting mxd to pdf using arcpy.mapping - ArcGIS 10 SP2

2067
13
07-20-2011 02:22 PM
DonovanCameron
Occasional Contributor II
I wrote a small python script that exports all mxd's in a folder to PDF's, but I get the following error in PyScripter and I don't know why...:
[ATTACH]7866[/ATTACH]

The python interpreter has whole bunch of red in it:
Found 5 mxds for PDF exporting...
Directory: C:\Users\is0009\Desktop\temp

Exporting Rural_OCP_map_1_17x11.mxd to:
C:\Users\is0009\Desktop\temp\Rural_OCP_map_1_17x11.pdf
Traceback (most recent call last):
  File "<string>", line 70, in execInThread
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\netref.py", line 123, in __call__
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\netref.py", line 45, in syncreq
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\protocol.py", line 343, in sync_request
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\protocol.py", line 305, in serve
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\protocol.py", line 265, in _recv
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\channel.py", line 36, in recv
  File "C:\Program Files (x86)\PyScripter\Lib\rpyc-python2x.zip\rpyc\core\stream.py", line 105, in read
EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host


Below is my script that I am trying:
The script is placed in a folder with a bunch of mxds.

#Import python modules
import os, sys, string, glob, arcpy
from arcpy import mapping

#Set local variables
mxdLst = glob.glob('*.mxd')
mxdCnt = len(mxdLst)
####
#Place script in same folder as MXDs to get 'current working directory'
####
baseF = os.getcwd()

#Print how many mxd's found
print '\n' + 'Found ' + str(mxdCnt) + ' mxds for PDF exporting...'
print 'Directory: ' + str(baseF) + '\n'

#Loop to process each mxd into a PDF
for mxds in mxdLst:
    PDFr = mxds.replace('mxd', 'pdf') #Replace 'mxd' extension with 'pdf'
    print 'Exporting ' + str(mxds) + ' to:' + '\n' + str(baseF) + '\\' + str(PDFr) #Print current mxd exporting and output pdf name...
    inMxd = arcpy.mapping.MapDocument(mxds) #Make current mxd in loop the mapdocument
    arcpy.mapping.ExportToPDF(inMxd, PDFr) #Export mapdocument to pdf
    print 'Done exporting: ' + str(PDFr)
del mxds
Tags (2)
0 Kudos
13 Replies
JakeSkinner
Esri Esteemed Contributor
Sounds like the problem is just with this specific MXD, so I don't think reverting back to 9.3.1 will help.  There are a couple other things you can try:

1.  Save the MXD to a new MXD (you can even try an earlier version of ArcGIS by using 'Save A Copy')
2.  Run the 'ArcGIS Document Defragmenter' on the MXD
3.  Run the 'MXD Doctor' on the MXD

Both of the utilities mentioned in 2 and 3 are located at Start > Programs > ArcGIS > Desktop Tools.
0 Kudos
JasonHarshman
Occasional Contributor
I use the Title property in the MXD to populate the PDF name in my batch exporting script.

import arcpy, os, sys, string

#overwirte existing PDFs
arcpy.OverWriteOutput = 1

#multimxds = string.split(arcpy.GetParameterAsText(0), ";")
multimxds = [filename[1:-1] for filename in string.split(arcpy.GetParameterAsText(0), ";")]
outputfolder = arcpy.GetParameterAsText(1)

#set variable for PDF name
#trying to set folder path
folderpath = outputfolder

#export to pdf
#trying to export to pdf using title name and folder parameter
for mxdloop in multimxds:
    mxd = arcpy.mapping.MapDocument(mxdloop)
    name = mxd.title
    pdf = folderpath + '\\' + name + ".pdf"
    arcpy.mapping.ExportToPDF(mxd, pdf, 'PAGE_LAYOUT', 640, 480, 400)

#delete folderpath variable
del folderpath


0 Kudos
StevenPorter
New Contributor
Sorry I'm a little late to the club. I just posted the script I wrote earlier this year. Simple but does a good job. There is much room for improvement, appreciate any feedback. Hopefully it helps you out.

http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=D8ED73DF-1422-2418-7F74-A6DCB...
0 Kudos
DonovanCameron
Occasional Contributor II
Sorry I'm a little late to the club. I just posted the script I wrote earlier this year. Simple but does a good job. There is much room for improvement, appreciate any feedback. Hopefully it helps you out.

http://resources.arcgis.com/gallery/file/geoprocessing/details?entryID=D8ED73DF-1422-2418-7F74-A6DCB...


Great job. This is very handy indeed!

Update on my little corrupt mxds: the things could not be saved with any mxd doctors so a little copy and pasting of the layouts was done into a new blank mxd then the scripts run fine.
0 Kudos