class ComboBoxClass4(object): """Implementation for MTR_addin.combobox (ComboBox)""" def __init__(self): self.value = "S" self.items = ("C", "F", "K", "S", "U") self.editable = True self.enabled = True self.dropdownWidth = 'WWW' self.width = 'WWW' def onSelChange(self, selection): pass def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass
Solved! Go to Solution.
def onSelChange(self, selection): self.sel = selection
combobox.sel
You need to use the ID from the addin assistant. In your case it is called 'combobox'
Then you probably changed it manually. Check in the addin assistant what the ID is for your combo box class. All you need are in the help docs.
http://resources.arcgis.com/en/help/main/10.2/index.html#/combo_box/014p00000028000000/
- <Toolbar caption="MTR Select" category="Township Select" id="MTR_addin.toolbar" showInitially="true"> - <Items> <Button refID="MTR_addin.button" /> <ComboBox refID="MTR_addin.combobox" /> <ComboBox refID="MTR_addin.combobox_1" /> <ComboBox refID="MTR_addin.combobox_2" /> <ComboBox refID="MTR_addin.combobox_3" /> <ComboBox refID="MTR_addin.combobox_4" /> </Items> </Toolbar> </Toolbars>
def onSelChange(self, selection): self.sel = selection
combobox.sel
print combobox? Are you trying to run this in an IDE? That won't work for addins. You'll only be able to reference the class values via the ID when it is installed as an addin. What is your end goal for this addin?
# --------------------------------------------------------------------------- # Township Selector # Created on: 2014-02-24 15:28:23.00000 # Create by Jason Graham # Usage: <NS> <EW> <Rng> <Twp> <M> <MTR> <MTRsel> # Description:Add-in tool to easily select a township then zoom to the selection # --------------------------------------------------------------------------- import arcpy import pythonaddins from arcpy import env env.workspace = r"X:\JasonGraham\Landstatus\Data\ls2014.gdb\BaseData" mxd = arcpy.mapping.MapDocument("CURRENT") class ComboBoxClass4(object): """Implementation for MTR_addin.combobox (ComboBox)""" def __init__(self): self.value = "S" self.items = ("C", "F", "K", "S", "U") self.editable = True self.enabled = True self.dropdownWidth = 'WWW' self.width = 'WWW' def onSelChange(self, selection): pass def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass Twp = [] for row in arcpy.SearchCursor("X:\JasonGraham\Landstatus\Data\ls2014.gdb\BaseData\Townships"): Twp.append(row.TWP_NUMC) class ComboBoxClass5(object): """Implementation for MTR_addin.combobox_1 (ComboBox)""" def __init__(self): self.value = "010" self.items = sorted(Twp) self.editable = True self.enabled = True self.dropdownWidth = 'WWWW' self.width = 'WWWW' def onSelChange(self, selection): global valName val = (self.items, selection)[1] valName = str(val) def onEditChange(self, text): pass def onFocus(self, focused):#show only unique values if focused: values = sorted(Twp) uniqueValues = set(values) self.items = [] for uniqueValue in uniqueValues: self.items.append(uniqueValue) def onEnter(self): pass def refresh(self): pass class ComboBoxClass6(object): """Implementation for MTR_addin.combobox_2 (ComboBox)""" def __init__(self): self.value = "N" self.items = ("N", "S") self.editable = True self.enabled = True self.dropdownWidth = 'WWW' self.width = 'WWW' def onSelChange(self, selection): pass def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass Rng = [] for row in arcpy.SearchCursor("X:\JasonGraham\Landstatus\Data\ls2014.gdb\BaseData\Townships"): Rng.append(row.RNG_NUMC) class ComboBoxClass7(object): """Implementation for MTR_addin.combobox_3 (ComboBox)""" def __init__(self): self.value = "010" self.items = sorted(Rng) self.editable = True self.enabled = True self.dropdownWidth = 'WWWW' self.width = 'WWWW' def onSelChange(self, selection): global valName val = (self.items, selection)[1] valName = str(val) def onEditChange(self, text): pass def onFocus(self, focused):#show only unique values if focused: values = sorted(Rng) uniqueValues = set(values) self.items = [] for uniqueValue in uniqueValues: self.items.append(uniqueValue) def onEnter(self): pass def refresh(self): pass class ComboBoxClass8(object):# Collect East/west def __init__(self): self.value = "E" self.items = ("E", "W") self.editable = True self.enabled = True self.dropdownWidth = 'WWW' self.width = 'WWW' def onSelChange(self, selection): selection def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): self.refresh() #concatenate inputs #MTRsel = combobox + Twp + combobox_2() + Rng(selected) + combobox_4() #print ComboBoxClass8(self) class ButtonClass3(object): """Implementation for MTR_addin.button (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): pass #arcpy.SelectLayerByAttribute_management("Townships","NEW_SELECTION",'"MTR" =' + "'%s'" %MTRsel) #arcpy.mapping.ListDataFrames(mxd)[0].zoomToSelectedFeatures() return None # Select user input value #arcpy.SelectLayerByAttribute_management("Townships","NEW_SELECTION",'"MTR" =' + "'%s'" %MTRsel) #gets error "ExecuteError: ERROR 000358: Invalid expression #arcpy.SelectLayerByAttribute_management("Townships","NEW_SELECTION",'"MTR" =' + MTRsel) gets error "TypeError: cannot concatenate 'str' and 'list' objects" #arcpy.SelectLayerByAttribute_management("Townships","NEW_SELECTION",MTRsel) gets error RuntimeError: Object: Error in executing tool #Zoom to selection #arcpy.mapping.ListDataFrames(mxd)[0].zoomToSelectedFeatures()