Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

You need to include empty quotes for parameters you aren't changing. Since resolution is the 6th parameter, you shouldn't place it directly after parameter 2 (out_jpeg). The empty quotes are place markers.

Example: arcpy.mapping.ExportToJPEG(mxd, project, "", "", "", resolution = 200)

You don't need to put quotes in for parameters after the last one you have defined.

Python isn't smart enough to figure out the order of parameters without explicitly telling it what is what. In your case, Python throws an error because you are defining parameter 6 in parameter 3's location.

Edit: I did some research and learned that you don't need to put in parameter space fillers if you explicitly state the parameter name in your code. I.e., since you put "resolution = 200" instead of just "200", Python should be able to figure out which parameter you are talking about. It shouldn't hurt to put in the empty quotes, but it isn't necessary if you explicitly state your parameter. That's why your original code was working fine.

Something you may test is explicitly adding default optional parameters to see if that works. For example,

arcpy.mapping.ExportToJPEG(mxd, project, data_frame = "PAGE_LAYOUT", resolution = 300)

worked on my machine. I'm not sure why the code works with some mxds and not others. My guess is that some mxds don't like the parameter syntax for some reason. Sorry I couldn't help more. Maybe some Python gurus can chime in.

share|improve this answer
    
This makes sense, but it's giving me the error after working fine on 10 or more maps already. Let's find out if it works! –  AlexGilvarry Oct 16 '12 at 16:52
2  
I don't have an explanation for that. I'm just giving a possible explanation for why you are getting the specific error you mentioned in your OP. Why it didn't have a problem with it before is beyond me. ESRI software is somewhat notorious for random bizarre effects. Have you changed ArcGIS versions recently? –  Baltok Oct 16 '12 at 16:56
    
When I added tbe empty quotes to the script it actually gave me this exception: "AttributeError: PageLayoutObject: Error in parsing arguments for ExportToJPEG" I dunno what to do with that... As far as changing versions recently, I upgraded to 10.1 when it came out a few months ago. –  AlexGilvarry Oct 18 '12 at 15:42
    
Well, I did some testing on my ArcGIS 10.0 machine and I get the same error you do. I don't know why it has a problem with the double quotes considering ESRI specifically mentions you can use it in their Python help. Also, I goofed a little on my original answer. See above edits. –  Baltok Oct 18 '12 at 18:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.