rikke

Python cannot set extent correctly

Discussion created by rikke on Jun 9, 2011
Latest reply on Aug 29, 2011 by deriven
Hi there,

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.

The code is:
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))


And the output is:
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


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...

Hopefully, its something obvious in there that I am missing,. Any help would be greatly appreicated.

Thanks in advance,
Richard.

Outcomes