Thanks so much Dan! I've implemented your suggestions into my code and it's working much better!I have another question; the combo box is populated with all SITE_NUM's when the user selects their first site. But the other sites that were available before disappear when the user tries to select a second site. That's why I originally created the "Selection" layer, above. One (partial) solution is to clear my selection in the onFocus function, but it's not ideal. Ideally I would like to maintain the selection so the user can generate a site report, etc. based on their selection, but still have the complete list of sites available to them for further selection later. Any thoughts?My new and improved code... 🙂
class ComboBoxClass1(object):
"""Implementation for Sites_addin.combobox (ComboBox)"""
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWW'
self.width = 'WWWWWWWWWW'
def onSelChange(self, selection):
layer = arcpy.mapping.ListLayers(mxd, "SITE", df)[0]
arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "SITE_NUM = '" + selection + "'")
df.extent = layer.getSelectedExtent()
arcpy.RefreshActiveView()
def onFocus(self, focused):
global mxd
mxd = arcpy.mapping.MapDocument('current')
global df
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
layer = arcpy.mapping.ListLayers(mxd, "SITE", df)[0]
arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
self.items = []
values = [row[0] for row in arcpy.da.SearchCursor(layer, ["SITE_NUM"])]
for uniqueVal in sorted(set(values)):
self.items.append(uniqueVal)
Thanks again.