Thursday, 14 September 2017

python - ExportToJPEG() arcpy script failure


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.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...