<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help - exporting data frame (not page layout) to PNG via arcpy in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698360#M54141</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good morning all&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to pull together some code to export the data view (not the page layout view) to PNG. The issue I'm having is that when I use the df variable in the ExportToPNG function, I am getting an Assertion Error. If I substitute df for "PAGE_LAYOUT" the script runs, but the output is not what I'm looking for.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas how to solve this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what I've got so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os from arcpy import env from time import localtime, strftime&amp;nbsp; # Set workspace&amp;nbsp; arcpy.env.workspace = r'd:\gis\aerialtracking\output' ws = arcpy.env.workspace if str(os.path.exists(ws)) == "False": &amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(ws)&amp;nbsp; # Set time variable and print output variable&amp;nbsp; printtime = strftime("%Y%m%d_%H%M", localtime()) print printtime pngname = "mapexport_" + printtime + ".png" print pngname&amp;nbsp; # Set mxd&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)&amp;nbsp; #Export PNG&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, pngname, df, df_export_width = 1600, df_export_height = 1200, world_file = True)&amp;nbsp; #delete variables&amp;nbsp; del df, ws, printtime, pngname, mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: I didn't actually get this above code to run, but I got similar code running thru the Python window in ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.mapping.ExportToPNG(mxd, r'D:\gis\aerialtracking\output\test.png', "PAGE_LAYOUT") &amp;gt;&amp;gt;&amp;gt; arcpy.mapping.ExportToPNG(mxd, r'D:\gis\aerialtracking\output\test.png', df) Runtime error &amp;lt;type 'exceptions.AssertionError'&amp;gt;:&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 15 Aug 2013 00:19:49 GMT</pubDate>
    <dc:creator>AnthonyCheesman1</dc:creator>
    <dc:date>2013-08-15T00:19:49Z</dc:date>
    <item>
      <title>Help - exporting data frame (not page layout) to PNG via arcpy</title>
      <link>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698360#M54141</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good morning all&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to pull together some code to export the data view (not the page layout view) to PNG. The issue I'm having is that when I use the df variable in the ExportToPNG function, I am getting an Assertion Error. If I substitute df for "PAGE_LAYOUT" the script runs, but the output is not what I'm looking for.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas how to solve this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This is what I've got so far:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy import os from arcpy import env from time import localtime, strftime&amp;nbsp; # Set workspace&amp;nbsp; arcpy.env.workspace = r'd:\gis\aerialtracking\output' ws = arcpy.env.workspace if str(os.path.exists(ws)) == "False": &amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(ws)&amp;nbsp; # Set time variable and print output variable&amp;nbsp; printtime = strftime("%Y%m%d_%H%M", localtime()) print printtime pngname = "mapexport_" + printtime + ".png" print pngname&amp;nbsp; # Set mxd&amp;nbsp; mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)&amp;nbsp; #Export PNG&amp;nbsp; arcpy.mapping.ExportToPNG(mxd, pngname, df, df_export_width = 1600, df_export_height = 1200, world_file = True)&amp;nbsp; #delete variables&amp;nbsp; del df, ws, printtime, pngname, mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit: I didn't actually get this above code to run, but I got similar code running thru the Python window in ArcMap.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.mapping.ExportToPNG(mxd, r'D:\gis\aerialtracking\output\test.png', "PAGE_LAYOUT") &amp;gt;&amp;gt;&amp;gt; arcpy.mapping.ExportToPNG(mxd, r'D:\gis\aerialtracking\output\test.png', df) Runtime error &amp;lt;type 'exceptions.AssertionError'&amp;gt;:&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 00:19:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698360#M54141</guid>
      <dc:creator>AnthonyCheesman1</dc:creator>
      <dc:date>2013-08-15T00:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Help - exporting data frame (not page layout) to PNG via arcpy</title>
      <link>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698361#M54142</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import os
from arcpy import env
from time import localtime, strftime

# Set workspace

arcpy.env.workspace = r'd:\gis\aerialtracking\output'
ws = arcpy.env.workspace
if str(os.path.exists(ws)) == "False":
&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(ws)

# Set time variable and print output variable

printtime = strftime("%Y%m%d_%H%M", localtime())
print printtime
pngname = "mapexport_" + printtime + ".png"
print pngname

# Set mxd

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)&lt;STRONG&gt;[0]&lt;/STRONG&gt;
#Export PNG

arcpy.mapping.ExportToPNG(mxd, pngname, df, df_export_width = 1600, df_export_height = 1200, world_file = True)

#delete variables

del df, ws, printtime, pngname, mxd&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Suspect the issue is that you are sending a list of dataframes to the export command rather than just one df as ListDataFrames always produces a list, even if only one item in it. the above code will use the first dataframe in the list (index [0]).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See if that gets it working,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:49:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698361#M54142</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-12T16:49:10Z</dc:date>
    </item>
    <item>
      <title>Re: Help - exporting data frame (not page layout) to PNG via arcpy</title>
      <link>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698362#M54143</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Spot on! Thank you - that has worked well.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kicking myself as I saw that in the example code but stupidly thought it was a comment, therefore didn't include it.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 01:01:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698362#M54143</guid>
      <dc:creator>AnthonyCheesman1</dc:creator>
      <dc:date>2013-08-15T01:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help - exporting data frame (not page layout) to PNG via arcpy</title>
      <link>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698363#M54144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Glad it worked for you.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, I see you gave me a point with the up arrow, would you might selecting the checkbox as answered also?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Will give me credit for it and also mark it answered for people searching similar issues in the future.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Aug 2013 01:02:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/help-exporting-data-frame-not-page-layout-to-png/m-p/698363#M54144</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2013-08-15T01:02:30Z</dc:date>
    </item>
  </channel>
</rss>

