ExportToPNG error

1097
13
02-14-2018 11:15 AM
Highlighted
New Contributor III

I have this code, which is basically copied from the online help:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.mapping.ExportToPNG(mxd, r"D:\t.png")‍‍‍

It generates this error:

Runtime error 
Traceback (most recent call last):
File "<string>", line 1, 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 1228, in ExportToPNG
layout.exportToPNG(*args)
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\arcobjects\mixins.py", line 586, in exportToPNG
return self._arc_object.exportToPNG(*args)
AttributeError: PageLayoutObject: Error in parsing arguments for ExportToPNG

Exporting the map using file, export, works fine. I tried making the path on C: and that fails too. I tried using exportToJPEG and got the same sort of error.

Reply
0 Kudos
13 Replies
Highlighted
MVP Regular Contributor

If you attempt to save the PNG to a location that you do not have permission, ArcMap will give an error like the one you received.

Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

The arcmap help topic for the current version of arcmap has a different code sample.  Perhaps the 10.3 version was incorrect ExportToPng help topic, But as Randy suggests it is more likely that you aren't allowed to write to the 😧 drive or it may be a USB drive or something not quite 'real'.  Try putting it in a folder in the drive r'D:\test\t.png' for instance

Reply
0 Kudos
Highlighted
New Contributor III

Thanks.

I tried this code after creating a D:\test folder: 

arcpy.mapping.ExportToPNG(mxd, r"D:\test\t.png")

I get the same error. I added "ALL APPLICATION PACKAGES" write permissions for the test folder but that didn't help.

D is a physical drive in my PC. All my data is stored on it; I don't have any trouble writing to it using the arcMap menus. 

I'm not sure if this is significant but if I run this code:

arcpy.mapping.ExportToPNG(mxd, r"D:\test\t.png", df)


Then I get a slightly different error:

Runtime error 
Traceback (most recent call last):
File "<string>", line 1, 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 1228, in ExportToPNG
layout.exportToPNG(*args)
AttributeError: DataFrameObject: Error in parsing arguments for ExportToPNG
Reply
0 Kudos
Highlighted
MVP Esteemed Contributor

In the first case, the 'AttributeError'  was associated with the PageLayoutObject and in the second it was the DataFrameObject, it is as if the object isn't being obtained suggesting that you need more than the *.mxd name... see line 2 below

mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") 
df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0]
arcpy.mapping.ExportToPNG(mxd, r"C:\Project\Output\ProjectDataFrame.png", df, df_export_width=1600, df_export_height=1200, world_file=True)
Reply
0 Kudos
Highlighted
New Contributor III

Thanks again.

I forgot to mention that I have:

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]


That part seems to be working because if I do

lyr = arcpy.mapping.ListLayers(mxd,"*Income",df)[0]
print lyr

Then it outputs the full name of the layer: "Median Household Income"

Reply
0 Kudos
Highlighted
MVP Regular Contributor

By any chance are you trying to overwrite an existing PNG? Also, there is a similar tool to export to PDF (arcpy.mapping.ExportToPDF).  If you try it, do you also get an error?

Reply
0 Kudos
Highlighted
New Contributor III

It is an empty folder.

I didn't try ExportToPDF but I did try ExportToJPEG and it gave me the same sorts of errors.

Reply
0 Kudos
Highlighted
MVP Regular Contributor

And file, export still works? Hmmm...

Reply
0 Kudos
Highlighted
New Contributor III

Yes. Exporting using the menus continues to work fine.

Reply
0 Kudos