I have an add-in script for a toolbox in ArcMap that lets a user select a data frame, a layer within it, a field from the layer, an operator (= , > , <, etc.), and a value from the field. I'm struggling to write a where_clause for the button class that is to execute the selection. I have global variables for each of the combo boxes, but I'm not unsure of how to translate the global variable for the field value to something usable in the Select By Attribute where_clause.
class OK(object): """Implementation for ok.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): mxd = arcpy.mapping.MapDocument("CURRENT") df = mxd.activeDataFrame arcpy.MakeFeatureLayer_management(layer, "layerSel") where_clause = "\"field\"= + '"+ valueS + "'" arcpy.SelectLayerByAttribute_management("layerSel","NEW_SELECTION",where_clause) df.zoomToSelectedFeatures() arcpy.RefreshActiveView()
layer, field, and valueS are the global variables for the user-chosen layer, field, and value, respectively.
This error appears when I run the script:
ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).
This I know has to do with the where_clause, I'm just now sure how to re-write it. I've read the Select Layer by Attribute article, as well as a few on SQL expressions, and I'm still very lost.