<?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 Re: MapFrame and using exportToPNG(), is this a bug? in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172730#M55022</link>
    <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;I've only tried to replicate the original problem (as highlighted on GIS SE) with 2 completely different datasets (both British National Grid). So I assume if I try a third dataset I would get the same problem.&lt;/P&gt;&lt;P&gt;For the record I'm using ArcPro 2.9.2 on a Windows 10 machine with 16GB of ram.&lt;/P&gt;&lt;P&gt;Yes when I ran it as a script in the python console I noticed it took a long time to complete, much longer than expected. If you export the whole layout using the Export Layout button on the Share tab it takes about 4 seconds...&lt;/P&gt;&lt;P&gt;It seems to me that the exporttoPNG() is not working correctly when its the mapframe that is being exported rather than the whole layout.&lt;/P&gt;</description>
    <pubDate>Wed, 11 May 2022 11:32:25 GMT</pubDate>
    <dc:creator>DuncanHornby</dc:creator>
    <dc:date>2022-05-11T11:32:25Z</dc:date>
    <item>
      <title>MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1167004#M54332</link>
      <description>&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;I came across this &lt;A href="https://gis.stackexchange.com/questions/429477/how-do-i-adjust-a-layouts-zoom-level-before-exporttopng" target="_self"&gt;Q&amp;amp;A&lt;/A&gt; on GIS Stack exchange, the poster wanted to export the MapFrame in a layout to a PNG which was zoomed to a feature defined by a definition query, but it creates a much large extent of output when exported&amp;nbsp;.&lt;/P&gt;&lt;P&gt;Someone answered, but their code does not really work. I adapted their code to adjust the extent of the MapView and camera objects, but like the original poster I too end up exporting a much larger PNG.&lt;/P&gt;&lt;P&gt;So my question is, is this by design or a bug in ArcPro 2.9.2 arcpy? If the MapFrame is showing a zoomed in section of the data I would have expected the export process to export only that?&lt;/P&gt;&lt;P&gt;The code is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.env.overwriteOutput = True

myPrj = arcpy.mp.ArcGISProject('current')
myLayout = myPrj.listLayouts("FirstPrintLayout")[0]
mapframe = myLayout.listElements("MAPFRAME_ELEMENT", "Map Frame 1")[0]

for lyr in mapframe.map.listLayers("River Centreline 2006"):
    if lyr.supports("DEFINITIONQUERY"):
        print(lyr.name, ' has defQuery ', lyr.definitionQuery)
        print ('Excellent! So now lets get the extents')
        mapExtent = mapframe.getLayerExtent(lyr)

        print (f'5 - mapFrame  XMin extents: {mapExtent.XMin}')
        print (f'Ymin {mapExtent.YMin}')
        print (f'XMax {mapExtent.XMax}')
        print (f'YMax {mapExtent.YMax}')
        
        mapframe.camera.setExtent(mapExtent)
        
        theMapView = myPrj.activeView # This line expects the Map to be Active Not Layout.
        theMapView.panToExtent(mapExtent)
               
        # Export Map Frame
        mapframe.exportToPNG(out_png='c:\Temp\outimg.png', resolution=60)
        print('Export completed!')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Note: my sample data is in British National Grid&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Apr 2022 15:28:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1167004#M54332</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2022-04-22T15:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1171585#M54854</link>
      <description>&lt;P&gt;Hello Duncan,&amp;nbsp; I can NOT reproduce the issue.&amp;nbsp; The script successfully sets the MF extent by zooming to the features that match the Def Query.&amp;nbsp;For me the exported PNG extent matches the MapFrame extent I see on the layout.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lines 21 and 22 do not make sense to me in the context of&amp;nbsp; exporting a MapFrame.&amp;nbsp; You must be running the script with the LayoutView active instead of the map view.&amp;nbsp; If I activate the MapView and run your script, it all works as expected:&amp;nbsp; The MapView extent is only panned, while the MapFrame extent is zoomed to the QueryDef features.&lt;/P&gt;&lt;P&gt;I tried all this on 2.9.&amp;nbsp; If you could provide more detail, I'd be happy to look futher.&lt;/P&gt;&lt;P&gt;Jeff - Layout and arcpy.mp teams&lt;/P&gt;</description>
      <pubDate>Fri, 06 May 2022 17:52:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1171585#M54854</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2022-05-06T17:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1171769#M54891</link>
      <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;Thanks for looking into this issue. Lines 21 &amp;amp; 22 were my attempt to see if the MapView was in some way overriding the MapFrame extent which gets sets by the definition query extent.&lt;/P&gt;&lt;P&gt;I wonder if the format of the data is in someway influencing the export process? E.g. is it a shapefile or geodatabase featureclass or do polygons work but not points?&lt;/P&gt;&lt;P&gt;How were you running the script, in the python console (as I had) or via notebook?&lt;/P&gt;&lt;P&gt;I will have another go and try it with some other dataset and report back.&lt;/P&gt;</description>
      <pubDate>Sat, 07 May 2022 10:10:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1171769#M54891</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2022-05-07T10:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172049#M54924</link>
      <description>&lt;P&gt;I was running your code in the Python Window.&amp;nbsp; You are more than welcome to send me a small PPKX so I can ensure we don't have an extent bug.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="mailto:jbarrette@esri.com" target="_blank"&gt;jbarrette@esri.com&lt;/A&gt;&amp;nbsp;- Layout and arcpy.mp teams&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 16:31:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172049#M54924</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2022-05-09T16:31:07Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172362#M54973</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1134"&gt;@JeffBarrette&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Here is a map package with a totally different dataset. I have applied a def query on one polygon (PID = 26), then run the code below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
arcpy.env.overwriteOutput = True

myPrj = arcpy.mp.ArcGISProject('current')
myLayout = myPrj.listLayouts("FirstPrintLayout")[0]
mapframe = myLayout.listElements("MAPFRAME_ELEMENT", "Map Frame 1")[0]

for lyr in mapframe.map.listLayers("fcTestData"):
    if lyr.supports("DEFINITIONQUERY"):
        print(lyr.name, ' has defQuery ', lyr.definitionQuery)
        print ('Excellent! So now lets get the extents')
        
        # Select zoom to then clear selection on the polygon defined in definition query
        sql = "PID = 26"
        arcpy.SelectLayerByAttribute_management(lyr,'NEW_SELECTION',sql)        
        mapExtent = mapframe.getLayerExtent(lyr,True)
        arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")

        print (f'5 - mapFrame  XMin extents: {mapExtent.XMin}')
        print (f'Ymin {mapExtent.YMin}')
        print (f'XMax {mapExtent.XMax}')
        print (f'YMax {mapExtent.YMax}')
        
        mapframe.camera.setExtent(mapExtent)
                       
        # Export Map Frame
        mapframe.exportToPNG(out_png='c:\Temp\outimg.png', resolution=60)
        print('Export completed!')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have modified the code slightly to zoom into the selected feature&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;sql = "PID = 26"&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(lyr,'NEW_SELECTION',sql)&lt;BR /&gt;mapExtent = mapframe.getLayerExtent(lyr,True)&lt;BR /&gt;arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So I open the project, open Python console and paste the above code in and run it. The output is an png zoomed to the extent of the layer, not the zoomed in selected feature, BUT the map fame has zoomed in, you can see this in the layout.&amp;nbsp; It seems to me that export process is not honouring the extent the map frame is displaying but that of the layer?&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 11:50:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172362#M54973</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2022-05-10T11:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172494#M54992</link>
      <description>&lt;P&gt;Thanks Duncan.&amp;nbsp; I can reproduce the issue with your data / script.&amp;nbsp; If I apply your scripting logic to data I have, I can NOT reproduce.&amp;nbsp; I will continue to dig.&amp;nbsp; I'm curious, is this the only data you can reproduce the issue with?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also - are you getting unusually slow export times?&amp;nbsp; For me, it is even slower if I modify your script to work outside of the application.&lt;/P&gt;</description>
      <pubDate>Tue, 10 May 2022 18:01:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172494#M54992</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2022-05-10T18:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172730#M55022</link>
      <description>&lt;P&gt;Jeff,&lt;/P&gt;&lt;P&gt;I've only tried to replicate the original problem (as highlighted on GIS SE) with 2 completely different datasets (both British National Grid). So I assume if I try a third dataset I would get the same problem.&lt;/P&gt;&lt;P&gt;For the record I'm using ArcPro 2.9.2 on a Windows 10 machine with 16GB of ram.&lt;/P&gt;&lt;P&gt;Yes when I ran it as a script in the python console I noticed it took a long time to complete, much longer than expected. If you export the whole layout using the Export Layout button on the Share tab it takes about 4 seconds...&lt;/P&gt;&lt;P&gt;It seems to me that the exporttoPNG() is not working correctly when its the mapframe that is being exported rather than the whole layout.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 11:32:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1172730#M55022</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2022-05-11T11:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1173766#M55142</link>
      <description>&lt;P&gt;Duncan,&lt;/P&gt;&lt;P&gt;We have your repro steps and we are looking into it.&amp;nbsp; In the meantime, a possible workaround it so customize the size of the Layout to be the same size as the MapFrame and then export the Layout instead of the MapFrame.&amp;nbsp; The layout is exporting with the proper map frame extent as you indicate.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 16:03:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1173766#M55142</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2022-05-13T16:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1173898#M55156</link>
      <description>&lt;P&gt;Duncan,&amp;nbsp; we figured it out.&amp;nbsp; MapFrames were hard-coded to pageunits=inches and you were using mm.&amp;nbsp; The extent was so far off because of the conversion from units to pixel space, etc.&amp;nbsp; We should have this fixed in Pro 3.0.&amp;nbsp; &amp;nbsp;So the work around continues to be what I suggested above or changing your page units to inches (which I know is not something you may want to do).&amp;nbsp; Thank you so much for reporting this.&amp;nbsp; I'm surprised it took so long to be discovered.&lt;/P&gt;&lt;P&gt;Jeff - Layout and arcpy.mp teams.&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2022 19:31:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1173898#M55156</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2022-05-13T19:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1174111#M55185</link>
      <description>&lt;P&gt;Jeff, thats great news. To be fair it was&amp;nbsp;@Maxcot&amp;nbsp;on GIS SE who discovered it. I recognised it as odd behaviour, not what I would have expected and something that needed resolving, hence me bringing it up on this forum. I personally have never attempted to export just a map frame usually for me it would be the whole layout.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 09:48:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1174111#M55185</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2022-05-16T09:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1575672#M91968</link>
      <description>&lt;P&gt;I'm also experiencing this issue; has it been fixed?&amp;nbsp; I'm using Arc Pro v3.3.2 and have this issue whether I run my script directly in Pro or standalone using VS Code (although it seems to take a good bit longer to export an image when running stand-alone).&amp;nbsp; The extent of the image defined in my script is much less than what is exported to png.&amp;nbsp; The X values of the layout extent update just fine and export correctly but the Y values keep getting overridden to the larger/random extent.&amp;nbsp; It doesn't seem to matter what map frame units I've selected or whether or not the 'preserve aspect ratio' is selected..&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like to not have to update the layout frame manually each time I export out an image.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2025 00:50:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1575672#M91968</guid>
      <dc:creator>jlgprime</dc:creator>
      <dc:date>2025-01-15T00:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1575992#M91998</link>
      <description>&lt;P&gt;@&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;jlgprime I can NOT reproduce this issue on released versions of the software.&amp;nbsp; Could you please provide a coordinate system and perhaps a couple of screen shots so I can try to reproduce your issue.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Jeff - arcpy.mp team&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV class=""&gt;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1575672#" target="_blank" rel="noopener"&gt;Preview&lt;/A&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Jan 2025 21:26:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1575992#M91998</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2025-01-15T21:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: MapFrame and using exportToPNG(), is this a bug?</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1576402#M92032</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/1134"&gt;@JeffBarrette&lt;/a&gt;the coordinate system I'm using is WGS 1984 Web Mercator (auxiliary sphere), WKID 3857, Linear Unit Meters (1.0).&amp;nbsp; FYI I notice that the extent that I specify in my code gets updated only in the Y dimension to match the aspect ratio of the page size set in the project layout, which in my case is 8.5 x 11.&amp;nbsp; Is there a setting to disable this for the purpose of running my script?&lt;/P&gt;&lt;P&gt;I should note that I was previously able to get the desired result using the similar Map View method, but ran into issues with not being able to adjust map rotation within my script (for other images), which I think I can accomplish with the Map Frame method.&amp;nbsp; Attached is the map view result (which I'm trying to obtain with my current code), a screenshot of the map frame in my project, and the result I'm currently getting with the Map Frame method.&amp;nbsp; Thanks again-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jan 2025 14:36:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/mapframe-and-using-exporttopng-is-this-a-bug/m-p/1576402#M92032</guid>
      <dc:creator>jlgprime</dc:creator>
      <dc:date>2025-01-16T14:36:12Z</dc:date>
    </item>
  </channel>
</rss>

