Hi All,
Trying to capture a variable from a combobox and use it on SQL query, but it doesn´t work.
Any idea how to create the variable "query"?
import arcpy
import pythonaddins
arcpy.env.workspace = r'C:/Users//Documents/Work/Access Resource/Propiedad Minera/Tools/PMdata.mdb'
arcpy.env.overwriteOutput = True
arcpy.env.addOutputsToMap = True
query = [County] = fc
class ButtonClass2(object):
"""Implementation for Test3_addin.button_1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
arcpy.MakeFeatureLayer_management("Properties","County_Layer",query)
class ButtonClass3(object):
"""Implementation for Test3_addin.button_2 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
pass
class ComboBoxClass1(object):
"""Implementation for Test3_addin.combobox (ComboBox)"""
def __init__(self):
self.items = ["Orange",Hiils ""]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWW'
self.width = 'WWWWWW'
def onSelChange(self, selection):
print"New Selection:",selection
fc =selection
def onEditChange(self, text):
pass
def onFocus(self, focused):
if focused:
self.mxd = arcpy.mapping.MapDocument('current')
layers = arcpy.mapping.ListLayers(self.mxd)
self.items = []
for layer in layers:
self.items.append(layer.name)
def onEnter(self):
pass
def refresh(self):
pass
Hi Sergio Pizarro,
The 3rd argument to the arcpy.MakeFeatureLayer_management() method is a where clause in SQL syntax. In your sample code you have:
query = [County] = fc
This line of code is not a valid SQL syntax, nor is it valid Python syntax.
In this case, the query variable must be a string, so you should put single quotes around the clause.
Here is a doc which goes into SQL syntax for where clauses in more detail:
Go ahead and try that. In the meantime I'm going to move your post to the Python community space for you to hopefully get more help on this if needed:
https://community.esri.com/community/developers/gis-developers/python/content