Export layout to jpeg

889
4
01-29-2021 05:09 AM
Official4
New Contributor

I want to export my layout to jpeg using arcpy but I was getting this error "Runtime error
Traceback (most recent call last):
File "<string>", line 22, in <module>
File "c:\program files (x86)\arcgis\desktop10.8\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.8\arcpy\arcpy\mapping.py", line 1026, in ExportToJPEG
layout.exportToJPEG(*args)
File "c:\program files (x86)\arcgis\desktop10.8\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.8\arcpy\arcpy\arcobjects\mixins.py", line 608, in exportToJPEG
return self._arc_object.exportToJPEG(*args)
AttributeError: PageLayoutObject: Error in executing ExportToJPEG". I change the path to different folder and it worked. I am now getting the same errors again. What could be the cause and any workaround?  

Tags (2)
0 Kudos
4 Replies
by Anonymous User
Not applicable

If you share your code, we can provide better help.

Official4
New Contributor

outpath = 'C:\Users\JOE\Desktop\maps\DUNKWA A/' + str(row.SOCIETY) + str(row.FID) + '.jpg'
arcpy.mapping.ExportToJPEG(mxd,outpath)

0 Kudos
by Anonymous User
Not applicable

Well,  putting that string into python and trying to print it raises an unicode error in python 3.6.  It printed when I treated it as a raw string and used formatting.  Used some dummy values since I don't know what your row.society or row.FID is.

print(r'C:\Users\JOE\Desktop\maps\DUNKWA A\{}{}.jpg'.format(str('Geo'), str('net')))

print(r'C:\Users\JOE\Desktop\maps\DUNKWA A\{}{}.jpg'.format(str(row.SOCIETY), str(row.FID)))

 

prints:  C:\Users\JOE\Desktop\maps\DUNKWA A\Geonet.jpg

Tomasz_Tarchalski
New Contributor III

Hi,

When using arcpy and python, make sure that you add r'' ('raw string') before the path. so for example:

outputpath = r'C:\Temp\MyFolder'

You coul also write like this:

outputpath = "C:\\Temp\\MyFolder"

or

outputpath = 'C:/Temp/MyFolder'

0 Kudos