Looping mxd's and clearing memory

723
1
09-07-2011 12:06 PM
MikeMacRae
Occasional Contributor III
Hey people,

I am trying to run a script for some batch printing and pdf'ing. I am running it against a directory with 3 mxd's in it. My script runs through fine, but as each mxd prints, they progressively start missing data. i.e the first mxd prints fine, the second one starts to lose some of the data in the map (portions of dataframe, text elements, legends, etc) and the third mxd prints almost nothing. I have a feeling it's a memory issue, but I'm unsure where to clear memory in the script.

I have attempted to increase my metafile memory allocation to as high as it goes (200 mb), but that hasn't helped either.

import sys, arcpy, traceback
import os
import glob

# Location of exported pdf's
exportpdf = r"Z:\ESRI\Figure_Sourcing\Figures\PDF\Export_Test\\"

# Provide folder path to loop through (first level only)
folderPath = r"Z:\ESRI\Figure_Sourcing\Figures\TestFigs\Test_Print"


for filename in glob.glob(os.path.join(folderPath, "*.mxd")):

        fullpath = os.path.join(folderPath, filename)
        
        mxd = arcpy.mapping.MapDocument(filename)
       
        arcpy.mapping.PrintMap(mxd, r"\\chip\Xerox 7655 (Upstairs)")
##        del mxd
##        del filename
##        del fullpath

        if os.path.isfile(fullpath):
            basename, filename2 = os.path.split(fullpath)
            #print basename
            #print filename2
            shortname, extension = os.path.splitext(filename2)
            print shortname
            arcpy.mapping.ExportToPDF(mxd, exportpdf + shortname, "PAGE_LAYOUT")
            del mxd
            del shortname
            del basename
            del filename2
            del filename
            del extension
Tags (2)
0 Kudos
1 Reply
MathewCoyle
Frequent Contributor
If you are having memory issue you need to make your metafile as SMALL as possible, not bigger. It could also be an issue with your printer running out of memory, even with a print server we noticed this on our plotters. This is exacerbated when using high DPI outputs. Try running the script without the pdf export, or vice versa, and see if you still get the issue.
0 Kudos