1

I'm having trouble with the button class of my code:

class OKButton(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.SelectLayerByAttribute_management(layer,"NEW_SELECTION",valueS)
    df.zoomToSelectedFeatures()
    arcpy.RefreshActiveView()                     

The toolbar allows the user to select a data frame, a layer within it, a field within that layer, and a value within that field. In the above code, "layer" and "valueS" are the global variables referring to the chosen layer and value within one of its fields, respectively. However, when I run the code this error is raised:

ExecuteError: ERROR 000358: Invalid expression Failed to execute (SelectLayerByAttribute).

I know I need to replace the where_clause with an SQL expression based on the value the user selects (currently the global variable "value"). How could I go about this?

  • 1
    You need to create a string to hold your sql expression. Look at the examples for Select Layer By Attributes and there are many examples on this forum. You have made no attempt at it yet – BERA May 11 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.