Search attribute and zoom to selected

1978
5
04-06-2012 07:19 AM
MatthewCory
New Contributor
So, I am completely new to Python, I do have experience in VBA but this is getting me tripped up.

I did get a script to work to select by attribute and zoom to the selected. I do have everything hard coded in but do want to have the geocode as a variable that the user inputs to a dialog box. I think I have the whole variable thing figured out. My issue is getting the input box for the user. Everything I have been able to find is confusing and I can't get to work.

If someone could point me in a direction to find some help related to getting a dialog box for the user to input the geocode then run the script I would be very appreciative.
Tags (2)
0 Kudos
5 Replies
markdenil
Occasional Contributor III
If you have a command line, raw_input() is quick and dirty.
Python GUI graphics start with Tkinter, which is relativly simple.
Although they can get a lot more complex and sophistcated from there, Tkinter is the place to start.
0 Kudos
MatthewCory
New Contributor
Thanks for the quick reply. Do I really need something like that? It will be more like a tool, isn't there a way to use what Arcmap has already?
0 Kudos
markdenil
Occasional Contributor III
If you are making the script a tool, then include the input as a parameter.
That way, the tool dialog will have an input field that can be configured in the tool set up process.
See Creating script tools for geoprocessing tasks
0 Kudos
DougKnight
New Contributor II
I also have a select and zoom to model/python script, and it works inside arcmap, but the service will not zoom to the select feature once inside a gp service.  can you possibly provide the code you used for the zoom to selected?
0 Kudos
MatthewCory
New Contributor
Here is what I used. Not sure if it is perfect, but it works for me...

import arcpy, arcgisscripting
gp = arcgisscripting.create()
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
Parcel = gp.GetParameterAsText(0)
whereClause = "GEOCODE ='%s'" % Parcel
arcpy.SelectLayerByAttribute_management ("Parcels", "NEW_SELECTION", whereClause)


showMessage("Parcel not found. Please try again.")

df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
0 Kudos