I work with arcview 10.3, and i try to extent to xy coordinate with arcpy?

I am using this code:

import arcpy, os, sys
from arcpy import env

env.workspace = r"C:\Project"
pnt = '178434 ,662446'
for mxdname in arcpy.ListFiles("*.mxd"):
    print mxdname
    mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
    df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] 
    df.extent = pnt
    print 'extent'
del mxd

but i get en error:

ValueError: Invalid string value for Extent argument

1 Answer 1


you need (at least) 4 values to define an extent. And you should provide those values in a list of numbers or using the properties of the extent object (e.g. XMin), not in a string. For example

df = arcpy.mapping.ListDataFrames(mxd)[0]
newExtent = df.extent
newExtent.XMin, newExtent.YMin = -180.0, -90.0
newExtent.XMax, newExtent.YMax = 180.0, 90.0
df.extent = newExtent

EDIT: in order to zoom "to a point", you still need to set an extent window (a point has no dimension). For example (zoom on a square of 200*200 centered on your point)

pointX, pointY = 178434, 662446
size = 100
newExtent.XMin, newExtent.XMax = pointX - size, pointX + size
newExtent.YMin, newExtent.YMax = pointY - size, pointY + size
  • but i want to zoom to specific xy coordinate,how can i do it? maybe it wrong to use extent operation?
    – newGIS
    Commented Jan 8, 2015 at 9:17
  • well, then you can compute the corners of your extent based on your central value. See my edit
    – radouxju
    Commented Jan 8, 2015 at 9:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.