Select to view content in your preferred language

Creating a Custom Toolbar Button

2516
5
09-07-2011 09:14 AM
KimBeckwell
Deactivated User
Hi,
I'm not sure if this is where I should post this but if someone could point me in the right direction of learning how to do this, I'd be forever grateful.....I would like to create a custom toolbar button that I can add to my ArcMap.mxd that will run a select and prompt me for a parcel number, and after keying the number in it will zoom to the selected parcel.

I would appreciate any help! Thanks!

Kim
Tags (2)
0 Kudos
5 Replies
KimBeckwell
Deactivated User
Should I use a VBA macro?
0 Kudos
MathewCoyle
Honored Contributor
If you just need to enter a value and zoom to that feature you can make a simple script tool, something along these lines. Add it to a toolbox and then make it a button.

import arcpy
arcpy.AddMessage("Starting")
city = arcpy.GetParameterAsText(0)
arcpy.AddMessage(city)
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Main Map")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Cities, Towns and Urban Service Areas", df)[0]
arcpy.AddMessage(lyr.name)
expression = "NAME = '"+city+"'"
arcpy.AddMessage(expression)
arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",expression)
df.extent = lyr.getSelectedExtent()
df.scale = df.scale*1.2
arcpy.RefreshActiveView()
0 Kudos
KimBeckwell
Deactivated User
Matthew, You are awesome! Thank You!
0 Kudos
JacobDrvar
Emerging Contributor
All,

I am new to Python scripting.  I am attempting to modify the code provided.  I have a Parcels Feature Class and want to search based on a RENUM attribute field.  I am running into a SyntaxError on line 5 .  Any ideas why?  Thanks.

0 Kudos
JacobDrvar
Emerging Contributor
I am modifying the script to Search the field RENUM from a Parcels Feature Class.  When, I run the script I receive the following error:
Executing: SelectLayerByAttribute GPL0 NEW_SELECTION 2205529
Start Time: Thu Jul 18 07:56:47 2013
ERROR 000358: Invalid expression
An invalid SQL statement was used.
An invalid SQL statement was used. [Parcels]
An invalid SQL statement was used. [SELECT OBJECTID FROM Parcels WHERE 2205529]
Failed to execute (SelectLayerByAttribute).

2205529 is a valid record within the RENUM field that I enter into the Script.  The tool runs, but the record is not selected.  What am I overlooking?

My script is shown below:


#Import modules
import arcpy
arcpy.AddMessage("Start")

#Variables
Parcels = arcpy.GetParameterAsText(0)
arcpy.AddMessage(Parcels)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Parcels", df)[0]
arcpy.AddMessage(lyr.name)

#Logic
try:
 whereClause = "RENUM = '"+Parcels+"'"
 arcpy.AddMessage("whereClause")

 arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
 arcpy.AddMessage("Selection")

except:
 exit()
0 Kudos