# Python Add-In Combo Box Not Working Properly

I am trying to create a python add-in toolbar with a combo box that lists all of the [SITE_NUMBER] values in my "Site Inspection" polygon layer. The user should be able to select a [SITE_NUMBER] value from the combo box and have the active map view zoom to the extent of the selected site. The problem is that the toolbar doesn't behave consistently. It works correctly if the "Site Inspection" layer is the only one in the MXD. If there is another layer in the MXD then the combobox only works a single time and then stops working completely. I'm new to python and add-ins so I'm not sure where I'm going wrong.

import arcpy

class ComboBoxClass1(object):
def __init__(self):
self.editable = True
self.enabled = True
self.dropdownWidth = '1234567'
self.width = '1234567'

def onSelChange(self, selection):
layer = arcpy.mapping.ListLayers(mxd, "Inspection Site", df)[0]
arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "SITE_NUMBER = '" + 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, "Inspection Site", df)[0]
arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
self.items = []
values = [row[0] for row in arcpy.da.SearchCursor(layer, ["SITE_NUMBER"])]
for uniqueVal in sorted(set(values)):
self.items.append(uniqueVal)

• Have you tried to get your Map Page Grid layer with his datasource? Try getting your layer with layer=arcpy.mapping.Layer(r"c:\datasource") – CptGasse Mar 28 '18 at 19:35
• Sorry for the delay. Where would i add that in the code exactly? – kbrenn89 Apr 5 '18 at 14:19
• I would replace the 2 line: layer = arcpy.mapping.ListLayers(mxd, "Inspection Site", df)[0] by layer=arcpy.mapping.Layer(r"c:\your\path\to\InspectionSite.shp") – CptGasse Apr 5 '18 at 18:17