I have a folder of 28 mxds that I'm trying to export all of them into 28 JPEGs. I'm having difficulty with the script and I'm hoping someone can help figure where I went wrong. Basically, I want to be export to run automatically, so that I don't have to open each mxd to export them into JPEGs.

    import arcpy, os
>>> folderPath = r"H:\Users\2015\Map15-0001\Zone Maps - for External Website"
>>> for filename in os.listdir(folderPath):
...     fullpath = os.path.join(folderPath, filename)
...     if os.path.isfile(fullpath):
...         basename, extension = os.path.splitext(fullpath)
...         if extension.lower() == ".mxd":
...             mxd = arcpy.mapping.MapDocument(fullpath)
...             df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
...             arcpy.mapping.ExportToJPEG(mxd, r"H:\Users\2015\Map15-0001\Zone Maps - for External Website\New"+basename+".jpg", df,resolution = 1000)

This is the error that I'm getting:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\utils.py", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\mapping.py", line 1026, in ExportToJPEG
AttributeError: DataFrameObject: Error in parsing arguments for ExportToJPEG

The mxds all have Data Driven Pages running on them. I was able to previously take all of the mxds and export separate PDFs.

I'm running ArcMap 10.3.

  • Do they all have dataframes "Layers"? – FelixIP Nov 8 '17 at 17:40
  • Yes, they all do. Also, all the mxds have an inset map with the generic "new data frame". Does that make a difference? – user108747 Nov 8 '17 at 18:07
  • I'd experiment with 1st in a list by disabling data pages and export without dataframes. Break loop to save time when debugging. – FelixIP Nov 8 '17 at 19:36

Based upon your code and subsequent comments it sounds like you want to export the layout rather than the dataframe? If so simply replace the df object with the string "PAGE_LAYOUT" in ExportToJPEG().

| improve this answer | |

I think the concatenation is messing up in your export to jpeg call. Try using formatting instead of concatenation:

arcpy.mapping.ExportToJPEG(mxd, "H:\\Users\\2015\\Map15-0001\\Zone Maps - for External Website\\New{0}.jpg".format(basename), df,resolution = 1000)


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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