BrokenLegMike

Looping mxd's and clearing memory

Discussion created by BrokenLegMike on Sep 7, 2011
Latest reply on Sep 7, 2011 by mzcoyle
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

Outcomes