AnsweredAssumed Answered

If i have the extents for a layer how do i get ArcGIS to center the drawing

Question asked by rhawk204 on Jan 8, 2020
Latest reply on Jan 8, 2020 by rhawk204

I have the following code:

import arcpy

#mxd = arcpy.mapping.MapDocument("CURRENT")
mxd = arcpy.mapping.MapDocument(r"C:/GISMAPS/LUS Map.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
OHLayer = arcpy.mapping.ListLayers(mxd, "Primary OH", df)[0]

df.extent = OHLayer.getSelectedExtent(False)
#df.scale = df.scale * 1.1
extent = ({df.extent.XMin}, {df.extent.YMin}, {df.extent.XMax}, {df.extent.YMax})

print('XMin: {}, YMin: {}'.format(df.extent.XMin, df.extent.YMin))
print('XMax: {}, YMax: {}'.format(df.extent.XMax, df.extent.YMax))

arcpy.RefreshActiveView()
del mxd

This is the output for lines 12 and 13

 

 

How do i center this drawing so that section of map is displayed on the screen? I have the extents but do not know how to use them to do this.

Thanks for any help.

Outcomes