Select to view content in your preferred language

ExportToPNG error

2819
13
02-14-2018 11:15 AM
RobertRogers
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.

0 Kudos
13 Replies
RandyBurton
MVP Alum

Are you running your code in the Python window inside ArcMap?  Or are you using an IDE outside ArcMap?

0 Kudos
ChrisPedrezuela
Occasional Contributor III

if you do not need to specify a dataframe for your output, just try replace df variable with string "PAGE_LAYOUT".

if you are specifying a dataframe, make sure your wildcard string to filter the dataframe name is correctly spelled? maybe a typo error or an extra white space at the end of the dataframe name?

0 Kudos
RobertRogers
New Contributor III

Thanks.

I tried "PAGE_LAYOUT" and it gave similar results. I also tried not providing anything and that didn't work either.

The wildcard filter is *Income, and lry reports that it is Median Household Income, so I think the wildcard is working properly.

0 Kudos
RobertRogers
New Contributor III

Things are working now.

I decided to upgrade from 10.3 to 10.6. After quitting all my running programs and starting the install process, the installer complained that ArcMap was still running. Task manager showed that it was still running, and using 13% of the CPU.

I suspect that the phantom ArcMap instance must have been doing something that was causing the problems. I should have taken my own advice and restarted the PC and I bet it would have worked from the start!