<?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: Python cannot set extent correctly in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710762#M55090</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you sure that is the same aspect ratio as the dataframe? You cant change to an extent that doesnt fit the frame. It looks like the dataframe object took your xmax and just calculated the other three to fit. Not that thats a useful function. Try changing two or three attributes and letting the others be generated to see if you get the proper extent.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 09 Jun 2011 14:06:03 GMT</pubDate>
    <dc:creator>ChrisMathers</dc:creator>
    <dc:date>2011-06-09T14:06:03Z</dc:date>
    <item>
      <title>Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710761#M55089</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi there,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am using the script from David Spriggs that prints a map to PDF. I am having a problem with the code "applying" the new extent to the map before printing.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The code is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.AddMessage("Input extent pts: %s %s %s %s" % (newPntLL.X, newPntLL.Y, newPntUR.X, newPntUR.Y))

myExtent = dataFrame.extent
arcpy.AddMessage("Original extent pts: %s %s %s %s" % (myExtent.XMin, myExtent.YMin, myExtent.XMax, myExtent.YMax))
arcpy.AddMessage("... setting my extent xmin to: %s" % newPntLL.X)
myExtent.XMin = newPntLL.X
arcpy.AddMessage("... setting my extent ymin to: %s" % newPntLL.Y)
myExtent.YMin = newPntLL.Y
arcpy.AddMessage("... setting my extent xmax to: %s" % newPntUR.X)
myExtent.XMax = newPntUR.X
arcpy.AddMessage("... setting my extent ymax to: %s" % newPntUR.Y)
myExtent.YMax = newPntUR.Y
arcpy.AddMessage("New extent pts: %s %s %s %s" % (myExtent.XMin, myExtent.YMin, myExtent.XMax, myExtent.YMax))
dataFrame.extent = myExtent

arcpy.AddMessage("Final MAP extent pts: %s %s %s %s" % (dataFrame.extent.XMin, dataFrame.extent.YMin, dataFrame.extent.XMax, dataFrame.extent.YMax))&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the output is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;Input extent pts: 3448672.2243 -3490621.8401 3449675.4603 -3490056.9226
Original extent pts: 2055276.37123 -4018755.96024 2055518.36111 -4018583.26583
... setting my extent xmin to: 3448672.2243
... setting my extent ymin to: -3490621.8401
... setting my extent xmax to: 3449675.4603
... setting my extent ymax to: -3490056.9226
New extent pts: 2055518.36111 -4018583.26583 3449675.4603 -3490056.9226
Final MAP extent pts: 2055518.36111 -4251785.42335 3449675.4603 -3256854.76508&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Baffling! Why does myExtent.XMin not show the 3448672 value? Its being explicitly defined there. Whats more confusing, is that it DOES show myExtent.XMax correctly... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully, its something obvious in there that I am missing,. Any help would be greatly appreicated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Richard.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jun 2011 11:51:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710761#M55089</guid>
      <dc:creator>RichardKaufholz</dc:creator>
      <dc:date>2011-06-09T11:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710762#M55090</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Are you sure that is the same aspect ratio as the dataframe? You cant change to an extent that doesnt fit the frame. It looks like the dataframe object took your xmax and just calculated the other three to fit. Not that thats a useful function. Try changing two or three attributes and letting the others be generated to see if you get the proper extent.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jun 2011 14:06:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710762#M55090</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2011-06-09T14:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710763#M55091</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Chris.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your thoughts. I tested with your idea by manually inputting the extent values - which I collected manually by viewing an extent within the map layout template itself (i.e. definitely fits).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;modified code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.AddMessage("Input extent pts: %s %s %s %s" % (newPntLL.X, newPntLL.Y, newPntUR.X, newPntUR.Y))

myExtent = dataFrame.extent
arcpy.AddMessage("Original extent pts: %s %s %s %s" % (myExtent.XMin, myExtent.YMin, myExtent.XMax, myExtent.YMax))
arcpy.AddMessage("... setting my extent xmin to: 3449977")
#myExtent.XMin = newPntLL.X
myExtent.XMin = 3449977
arcpy.AddMessage("... setting my extent ymin to: -3492834")
#myExtent.YMin = newPntLL.Y
myExtent.YMin = -3492834
arcpy.AddMessage("... setting my extent xmax to: 3450982")
#myExtent.XMax = newPntUR.X
myExtent.XMax = 3450982
arcpy.AddMessage("... setting my extent ymax to: -3492116")
#myExtent.YMax = newPntUR.Y
myExtent.YMax = -3492116
arcpy.AddMessage("New extent pts: %s %s %s %s" % (myExtent.XMin, myExtent.YMin, myExtent.XMax, myExtent.YMax))
dataFrame.extent = myExtent

arcpy.AddMessage("Final MAP extent pts: %s %s %s %s" % (dataFrame.extent.XMin, dataFrame.extent.YMin, dataFrame.extent.XMax, dataFrame.extent.YMax))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the modified output:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Input extent pts: 3448672.2243 -3490621.8401 3449675.4603 -3490056.9226
Original extent pts: 2055276.37123 -4018755.96024 2055518.36111 -4018583.26583
... setting my extent xmin to: 3449977
... setting my extent ymin to: -3492834
... setting my extent xmax to: 3450982
... setting my extent ymax to: -3492116
New extent pts: 2055518.36111 -4018583.26583 3450982.0 -3492116.0
Final MAP extent pts: 2055518.36111 -4253281.1636 3450982.0 -3257418.10223
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, now with confirmed coordinates, the values are &lt;/SPAN&gt;&lt;STRONG style="font-style: italic;"&gt;still &lt;/STRONG&gt;&lt;SPAN&gt;not sticking to the extent variables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Richard.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why cant computers just do what they are told?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:27:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710763#M55091</guid>
      <dc:creator>RichardKaufholz</dc:creator>
      <dc:date>2021-12-12T06:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710764#M55092</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;That wouldnt be any fun though &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;It could also be that once an extent object is created the properties are read only. &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Extent/000v0000006r000000/"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Extent/000v0000006r000000/&lt;/A&gt;&lt;SPAN&gt; You were trying to edit a static object.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;myExtent=arcpy.Extent(3449977,-3492834,3450982,-3492116)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dataFrame.extent = myExtent&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jun 2011 11:49:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710764#M55092</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2011-06-10T11:49:47Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710765#M55093</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, "fun" is one way to put it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here are three, &lt;/SPAN&gt;&lt;STRONG&gt;very&lt;/STRONG&gt;&lt;SPAN&gt; compelling, reasons why your suggestion will not work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1. The original code for this section is taken (unedited) from a working sample posted by David Spriggs at ESRI&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. It has worked in the past (cant really say under which circumstances it did work unforatuntely...)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. The "readonly" variables for xmax and ymax &lt;/SPAN&gt;&lt;STRONG&gt;are&lt;/STRONG&gt;&lt;SPAN&gt; set correctly, but the xmin and ymin are not&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And yet, despite that very clear evidence, your suggestion has worked.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sometimes, I really dont know why I do this! But thanks a million for your help - lifesaver!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Richard.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jun 2011 12:43:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710765#M55093</guid>
      <dc:creator>RichardKaufholz</dc:creator>
      <dc:date>2011-06-10T12:43:41Z</dc:date>
    </item>
    <item>
      <title>Workaround sets new dataframe extent properly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710766#M55094</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I saw very similar results in following the Dave Spriggs example for an export to PDF service we're running here.&amp;nbsp; It worked for weeks and then just stopped working about 3 weeks ago and as far as I can tell, no one upgraded/modified ArcGIS (Desktop, Server) anything on our server.&amp;nbsp; I tried the workaround of creating a new arcpy.Extent object and all seems fine with the new extent again.&amp;nbsp; Can't figure out why the published Spriggs example stopped working.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jul 2011 16:39:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710766#M55094</guid>
      <dc:creator>DavidHollema</dc:creator>
      <dc:date>2011-07-14T16:39:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710767#M55095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks from me too Chris&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I thought I was going crazy when I seemed to lose control over what I thought should be a very straightforward extent change.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;- Graeme&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Jul 2011 02:40:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710767#M55095</guid>
      <dc:creator>GraemeBrowning</dc:creator>
      <dc:date>2011-07-20T02:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710768#M55096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I believe this is what is causing the issue. First the extent of the data frame is defined as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;XMIN: 2055276.37123 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;YMIN:-4018755.96024 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;XMAX: 2055518.36111 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;YMax: -4018583.26583&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first thing the code tries to do is set the XMIN of the extent to 3448672.2243 which would give you the following extent:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;XMIN: 3448672.2243&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;YMIN:-4018755.96024 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;XMAX: 2055518.36111 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;YMax: -4018583.26583&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that now you have an extent where the XMIN is greater than the XMAX and this is not a valid extent so the software automatically changes XMIN to the closest valid value for the extent, 2055518.36111.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When you try to set XMAX to 3450982 it works fine because it is larger then XMIN. This code will work sometimes, but only in the events when you attempt to set a new XMIN or YMIN that is less than the XMAX or YMAX.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The better way to approach this would be like the option discussed by Chris Mathers to create a new extent object from your extent values and assign it to the extent of the dataframe.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;myExtent=arcpy.Extent(3449977,-3492834,3450982,-3492116)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dataFrame.extent = myExtent&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Jul 2011 19:59:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710768#M55096</guid>
      <dc:creator>ChrisFox3</dc:creator>
      <dc:date>2011-07-25T19:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710769#M55097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Incidentally, this situation also happens in ArcObjects.NET (which makes sense actually).&amp;nbsp; My YMIN would not hold -- probably because of what Chris_Fox states about the MAX value being less than the MIN value.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Creating a new envelope and assigning it does not work for me.&amp;nbsp; But changing the extent's xmin, ymin, xmax, and ymax (in that order) twice in a row did.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IEnvelope currentExtent = mapDoc.ActiveView.Extent.Envelope;
currentExtent.XMin = xmin;
currentExtent.YMin = ymin;
currentExtent.XMax = xmax;
currentExtent.YMax = ymax;
// And repeat...
currentExtent.XMin = xmin;
currentExtent.YMin = ymin;
currentExtent.XMax = xmax;
currentExtent.YMax = ymax;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I must have burned a couple of hours trying to blame this on my code.&amp;nbsp; Glad I finally found this post.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:27:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710769#M55097</guid>
      <dc:creator>DerivenC</dc:creator>
      <dc:date>2021-12-12T06:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710770#M55098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;So you find the following code doesn't work for you?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IEnvelope newExtent = new EnvelopeClass();
newExtent.XMin = xmin;
newExtent.XMax = xmax;
newExtent.YMin = ymin;
newExtent.YMax = ymax;
mapDoc.ActiveView.Extent.Envelope = newExtent&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason I ask is because I still see potential problems in your code in the scenario where the value you have in xmin or ymin is greater than the xmax or ymax of the current ActiveView Envelope.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:27:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710770#M55098</guid>
      <dc:creator>ChrisFox3</dc:creator>
      <dc:date>2021-12-12T06:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python cannot set extent correctly</title>
      <link>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710771#M55099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Well I found that my code works great for zooming to an extent but fails when displaying by scale and panning.&amp;nbsp; But yes I still have to set the numbers twice.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IEnvelope newEnvelope = mapDoc.ActiveView.Extent.Envelope;
newEnvelope.XMin = xMin;
newEnvelope.YMin = yMin;
newEnvelope.XMax = xMax;
newEnvelope.YMax = yMax;
newEnvelope.XMin = xMin;
newEnvelope.YMin = yMin;
newEnvelope.XMax = xMax;
newEnvelope.YMax = yMax;
mapFrame.MapBounds = newEnvelope;
mapFrame.ExtentType = esriExtentTypeEnum.esriExtentBounds;
activeView.Refresh();
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To get scale to work, I have to do the same thing.&amp;nbsp; Then I have to save the document and THEN pan to a center point.&amp;nbsp; It's the only way I could get it to work.&amp;nbsp; I tried for hours.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
IEnvelope newEnvelope = mapDoc.ActiveView.Extent.Envelope;
newEnvelope.XMin = xMin;
newEnvelope.YMin = yMin;
newEnvelope.XMax = xMax;
newEnvelope.YMax = yMax;
newEnvelope.XMin = xMin;
newEnvelope.YMin = yMin;
newEnvelope.XMax = xMax;
newEnvelope.YMax = yMax;
mapFrame.MapBounds = newEnvelope;
mapFrame.ExtentType = esriExtentTypeEnum.esriExtentBounds;
activeView.Refresh();

IPoint point = new Point();
point.X = ((xMin + xMax) / 2d);
point.Y = ((yMin + yMax) / 2d);
IEnvelope ab = mapFrame.MapBounds.Envelope;
ab.CenterAt(point);
mapFrame.MapBounds = ab;
activeView.Refresh();
Marshal.ReleaseComObject(activeView);
Marshal.ReleaseComObject(mapFrame);
Marshal.ReleaseComObject(frameElement);
Marshal.ReleaseComObject(graphicsContainer);
Marshal.ReleaseComObject(map);
SaveDocument();
OpenDocument();
map = mapDoc.ActiveView.FocusMap;
graphicsContainer = mapDoc.PageLayout as IGraphicsContainer;
frameElement = graphicsContainer.FindFrame(map);
mapFrame = (IMapFrame)frameElement;
activeView = (IActiveView)mapDoc.ActiveView;

mapFrame.ExtentType = esriExtentTypeEnum.esriExtentScale;
map.MapUnits = esriUnits.esriMeters;
mapFrame.MapScale = (double)request.scale;
activeView.Refresh();
Marshal.ReleaseComObject(point);
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Works though.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 06:27:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-cannot-set-extent-correctly/m-p/710771#M55099</guid>
      <dc:creator>DerivenC</dc:creator>
      <dc:date>2021-12-12T06:27:50Z</dc:date>
    </item>
  </channel>
</rss>

