AnsweredAssumed Answered

Creating a City Select and Zoom tool using arcpy

Question asked by gapullis on May 2, 2016
Latest reply on May 3, 2016 by wwmiller68

Working on creating a lab which will allow me to type in a city name into a parameter and it will select that city, add it to the TOC and zoom into it. I'm having trouble getting around certain errors. Please help!




import arcpy

from arcpy import mapping

#set workspace

mxd = arcpy.mapping.MapDocument("CURRENT")

#set the dataframe

df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

cities = arcpy.mapping.ListLayers(mxd, "Cities")[0]

#Establish variables

cityName = arcpy.GetParameterAsText(0)

#Set variable as the parameter for the city search

arcpy.SelectLayerByAttribute_management("Cities", "NEW_SELECTION", " CITY_NAME = 'cityName' ")