2

I am attempting to make a simple select and zoom python script for my address points. Currently the script will complete successfully but will not select or zoom to the entered point. I am using two parameters that have been set in the Script Tool. Address_Number (Long) and Address_Name (String) which both have identical spellings/data types in Properties>>Parameters

Here's the code:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
addLayer = arcpy.mapping.Layer("G:\Layers\GIS_SDE.AddressPoints.lyr")
arcpy.mapping.AddLayer(df, addLayer, "TOP")
Address_Number = arcpy.GetParameterAsText(0)
Address_Name = arcpy.GetParameterAsText(1
arcpy.SelectLayerByAttribute_management("GIS_SDE.AddressPoints", "NEW_SELECTION", "A_NBR = %Address_Number% AND ADDR = %Address_Name%")
df.zoomToSelectedFeatures()
2

The problem is the Where Clause that you are supplying to SelectLayerByAttributes.

I would recommend that you try the technique used by @blah238 in this answer to Including variable in where clause of arcpy.Select_analysis()?

You could do something like this to use the referenced function with multiple conditions/fields, joining them with the AND operator:

arcpy.SelectLayerByAttribute_management("GIS_SDE.AddressPoints",
"NEW_SELECTION",
" AND ".join(
    [buildWhereClause("GIS_SDE.AddressPoints", "A_NBR", Address_Number),
     buildWhereClause("GIS_SDE.AddressPoints", "ADDR", Address_Name)]))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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