I'm trying to script another Select by Attributes tool. I want to be able to find a specific building using a field and zoom in to the location. However, my tool needs to allow a user to input any field or any value. So far this is what I got.
#Import Modules import arcpy arcpy.env.workspace = "C:\Users\pierrej\Desktop\GIS Data" arcpy.env.overwriteOutput = True #Set to current mxd and dataframe mxd = arcpy.mapping.MapDocument ('CURRENT') df = arcpy.mapping.ListDataFrames(mxd,"Layers") try: # Set the tool parameters InputFeatureClass = arcpy.GetParameterAsText(0) InputField = arcpy.GetParameterAsText(1) InputValue = arcpy.GetParameterAsText(2) # SQL expression used in selecting a feature #Create the query qry = "\"InputField\" = InputValue" arcpy.MakeFeatureLayer_management(InputFeatureClass, "Layer") #Call the Select Layer by Attribute tool arcpy.SelectLayerByAttribute_management("Layer", "NEW_SELECTION", qry) #Zooming to a selection set for the specific layer df.zoomToSelectedFeatures() df.scale = 2500000 arcpy.RefreshActiveView() # Report a success message arcpy.AddMessage("All done!") #Print an error message in the event of a problem: except: print "An error occurred during selection"
My parameters are the following:
InputFeatureClass = Data Type: Feature Layer, Required, Input, No Multivalue
InputField = Data Type: Field, Required, Input, No Multivalue, Obtained from Input Feature Class
InputValue = DataType: String, Required, No Multivalue
The script runs and I don't have any error message but the tool doesn't select any thing. How can I fix this?