# This script runs the Select tool. The user supplies the input import arcpy # Get the input parameters for the Select tool infeatures = arcpy.GetParameterAsText(0) userinput = arcpy.GetParameterAsText(1) # Run the Select tool arcpy.Select_analysis(infeatures, "NEW_SELECTION", '\Job_Num\" = %s' % userinput)
It depends on what you want to do with the selected set, but typically I use the MakeFeatureLayer tool to apply rapid selections (runs faster than the SelectLayerByAttribute tool). The Select tool actually creates a new featureclass on disk, so has the additional overhead of writting to disk...
The MakeFeatureLayer tool creates a "feature layer" that is an in memory reference to the selcted features on disk (but does not actualy store the geometry/attributes in RAM). Then you can use the feature layer for input into other tools just as you would a feature class.
For example:
arcpy.MakeFeatureLayer_management(infeatures, "my_feature_layer", "Job_Num = " + str(userinput))
arcpy.Clip_analysis("my_feature_layer", ....)
See this Help topic: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000051000000
Try using the featurelayer's SQL 1st... You may "have to" use the SelectLayerByAttribute tool though... I am not totally familiar with the arcpy.mapping module.
# This script runs the Select tool. The user supplies the input
import arcpy
#Set the workspace
arcpy.env.workspace = "G:\\PRAD\\PRAD_v10.1.gdb"
#Retrieve input
userinput = arcpy.GetParametersAsText(0)
# Make a layer from the feature class based on whereclause from input
arcpy.MakeFeatureLayer_management ("tax_acct", "lyr", "Job_Num = " + str(userinput))
# Select that layer
arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION")
#Zoom to selected
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
df.zoomToSelectedFeatures()
df.scale = df.scale * 1.1
arcpy.RefreshActiveView()
# Clear the selection and refresh the active view
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
arcpy.RefreshActiveView()