<?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: setting data frame extent does not work in select cases in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/setting-data-frame-extent-does-not-work-in-select/m-p/385039#M30380</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thre was a bug in 10.0 that required one to set the dataframe extent twice, just to make sure it worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I had a similar problem, where it worked sometimes and then not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To fix it, after I set the extent I would then create a new instance of the data frame object and set the extent on that one too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That seemed to catch most all of the missed settings.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set extent (values in a list)
newExtent = df.extent
newExtent.XMin = extent[0]
newExtent.YMin = extent[1]
newExtent.XMax = extent[2]
newExtent.YMax = extent[3]
df.extent = newExtent
del newExtent

##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set extent a second time - v10 bug workaround"
df2 = arcpy.mapping.ListDataFrames(mxd, theFrame)[0]
anotherExtent = df2.extent
anotherExtent.XMin = extent[0]
anotherExtent.YMin = extent[1]
anotherExtent.XMax = extent[2]
anotherExtent.YMax = extent[3]
df2.extent = anotherExtent
del anotherExtent
 
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set rotation and scale
df.rotation = rotation
df.scale = scale&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 17:42:08 GMT</pubDate>
    <dc:creator>markdenil</dc:creator>
    <dc:date>2021-12-11T17:42:08Z</dc:date>
    <item>
      <title>setting data frame extent does not work in select cases</title>
      <link>https://community.esri.com/t5/python-questions/setting-data-frame-extent-does-not-work-in-select/m-p/385038#M30379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a python script that effectively creates a series of maps by iterating over a set of geodatabases and replaces data sources in a template file.&amp;nbsp; Part of the the script loops over the layers in the sole data frame and sets the extent of the data frame and the spatial reference based on those of a layer within.&amp;nbsp; After the loop I change the scale by using a multiplier, set the data frame spatial reference, and refresh my active view.&amp;nbsp; Example of code is below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # define data frame&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # set the utm spatial reference and zoom to layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "neat_contour_55":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print lyr.name&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.extent = lyr.getSelectedExtent()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sr = arcpy.Describe(lyr).spatialReference&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.scale = df.scale * 1.25&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; df.spatialReference = sr&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have used this portion of script before to change the data frame extent and it has worked successfully.&amp;nbsp; Recently I have run into an issue where about 5 percent of the maps I am attempting to create do not change extent.&amp;nbsp; The only thing that has changes in my system is that I have since upgraded to 10.1.&amp;nbsp; In the results, the spatial reference does change, and the data is properly replaced, but the extent upon which the map is focused remains where the data in the template resided.&amp;nbsp; For example, my template is based on Atlanta and I am mapping part of Seattle, and while the data is there, the map remains centered on Atlanta.&amp;nbsp; There is no error that occurs, the extent seems to be correct based on what I had printed during execution of my script, but the final map and associated pdf are incorrect and simply display the background states layer in the area of Atlanta.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If anyone has had any similar issues, or can offer any advice, it would be much appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Paul P.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Aug 2012 16:57:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-data-frame-extent-does-not-work-in-select/m-p/385038#M30379</guid>
      <dc:creator>PaulPadegimas</dc:creator>
      <dc:date>2012-08-15T16:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: setting data frame extent does not work in select cases</title>
      <link>https://community.esri.com/t5/python-questions/setting-data-frame-extent-does-not-work-in-select/m-p/385039#M30380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thre was a bug in 10.0 that required one to set the dataframe extent twice, just to make sure it worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I had a similar problem, where it worked sometimes and then not.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To fix it, after I set the extent I would then create a new instance of the data frame object and set the extent on that one too.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That seemed to catch most all of the missed settings.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set extent (values in a list)
newExtent = df.extent
newExtent.XMin = extent[0]
newExtent.YMin = extent[1]
newExtent.XMax = extent[2]
newExtent.YMax = extent[3]
df.extent = newExtent
del newExtent

##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set extent a second time - v10 bug workaround"
df2 = arcpy.mapping.ListDataFrames(mxd, theFrame)[0]
anotherExtent = df2.extent
anotherExtent.XMin = extent[0]
anotherExtent.YMin = extent[1]
anotherExtent.XMax = extent[2]
anotherExtent.YMax = extent[3]
df2.extent = anotherExtent
del anotherExtent
 
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set rotation and scale
df.rotation = rotation
df.scale = scale&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:42:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/setting-data-frame-extent-does-not-work-in-select/m-p/385039#M30380</guid>
      <dc:creator>markdenil</dc:creator>
      <dc:date>2021-12-11T17:42:08Z</dc:date>
    </item>
  </channel>
</rss>

