CaspianKid

Zoom to user-defined extent

Discussion created by CaspianKid on Apr 4, 2013
Latest reply on Apr 4, 2013 by CaspianKid
Hello all,

I am working on something that I think is pretty simple but it seems to be evading me at this time.  I have a layer "Counties" and want the user to pick a County using sys.argv and then have the map set that county as the data frame extent.  The Counties layer has the county name in the NAME field.

Here is the code I am using:

#Import modules
import os
import sys
import arcpy

#Set Map Document
mxd = arcpy.mapping.MapDocument("Current")

#Set Overwrite Option
arcpy.env.overwriteOutput = True

#Sets parameters (attributes)
CountyName = sys.argv[1]

#Gets Name value for definition query
rows = arcpy.SearchCursor("TexasCounties")
for row in rows:
    DefQuery= row.getValue("NAME")

#Set String Values for Definition Query
strName_DQ = "NAME = '" + DefQuery + "'"

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "TexasCounties", df)[0]
lyr.definitionQuery = strName_DQ
df.extent = lyr.getSelectedExtent()

del row
del rows

#Refresh Map to refelct Changes
arcpy.RefreshActiveView()
mxd.save()

del mxd,

Any help y'all could priovide would be appreciated.
Thanks.

Outcomes