[GIS] ExportToJPEG() arcpy script failure

.jpgarcpyexportpython

I'm attempting to writing a python script that will automate exporting a set of stock maps to JPEG from their mxd files, and I'm having some strange issues getting there.

I've alternatively been getting a Visual C++ Runtime error saying python experienced an abnormal program termination, or the program throws an exception saying "AttributeError: PageLayoutObject: Error in executing ExportToJPEG"

I've tried two main ways of running this process. In one I loop through an array of directories and pull the individual mxd files into the export command, as below:

for line in Direct:
    path = str(line) + "*.mxd"

    listing = os.listdir(path)
    for infile in glob.glob(path):
        mxd = arcpy.mapping.MapDocument(infile)
        infile = infile.split("\\")[-1]
        infile = infile.rstrip('.mxd')
        infile = infile + ".jpg"

        project = os.path.join(destpath, infile)
        arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

        del mxd

In the other form, I copy the arcpy.mapping.ExportToJPEG() line over and over with the parameters for each map specified, as below:

mxd = arcpy.mapping.MapDocument(r"Y:\Maps\map1.mxd")
project = "C:/Maps/map1.jpg"
arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

mxd = arcpy.mapping.MapDocument(r"Y:\Maps\map2.mxd")
project = "C:/Maps/map2.jpg"
arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

mxd = arcpy.mapping.MapDocument(r"Y:\Maps\map3.mxd")
project = "C:/Maps/map3.jpg"
arcpy.mapping.ExportToJPEG(mxd, project, resolution = 200)

I've tried multiple tests to see if my syntax is wrong, and if the script is using too many resources and crashing, but haven't been able to figure out what my issue is.

The weird part is I can't seem to find any pattern or reason to the maps I'm getting these errors on. It seems like it changes every time I alter my script.

Best Answer

This is old but I had the same error "PageLayoutObject: Error in executing ExportToJPEG". The problem for me was that I was trying to write to a folder that didn't exist. Once I created the folder, it worked fine. This also makes me think that if you had some other kind of permissions problem that didn't let you write to the output file it might also be expressed as this kind of an error.

Related Question