Select to view content in your preferred language

Select and Zoom Script

988
2
03-01-2013 01:48 PM
JordanBaltierra
New Contributor
Hi All, 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() 


Any help is appreciated.

Thanks,
Jordan
Tags (2)
0 Kudos
2 Replies
KimOllivier
Honored Contributor
I think your problem will be that a single point does not have an extent so you cannot zoom to it. You will have to create your own extent from the point by choosing a suitable buffer rectangle and zoom to that.
0 Kudos
JeffBarrette
Esri Regular Contributor
Another option is to zoom by setting the data frame scale.  You can either hard code it or change it relatively.

df.scale = df.scale / 2 (zoom in 2x)

Also - because you are using "current", don't forget to use arcpy.RefreshActiveView().

Jeff
0 Kudos