import arcpy import pythonaddins global mxd mxd = arcpy.mapping.MapDocument('current') global df df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] 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 onFocus(self, focused): layer = r"C:\...\SITE" self.items = [] values = [row[0] for row in arcpy.da.SearchCursor(layer, ["SITE_NUM"])] for uniqueVal in sorted(set(values)): self.items.append(uniqueVal) def onSelChange(self, selection): layer = r"C:\...\SITE" arcpy.MakeFeatureLayer_management(layer, "Selection") arcpy.SelectLayerByAttribute_management("Selection", "NEW_SELECTION", "SITE_NUM = '" + selection + "'") arcpy.RefreshActiveView() df.zoomToSelectedFeatures() arcpy.RefreshActiveView()Solved! Go to Solution.
layer_path = layer.dataSource
values = [row[0] for row in arcpy.da.SearchCursor(layer_path, ["SITE_NUM"])]
layer = arcpy.mapping.ListLayers(mxd, "Name of Layer", df)[0]
df.extent = layer.getSelectedExtent() arcpy.RefreshActiveView()
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)
layer_path = layer.dataSource
values = [row[0] for row in arcpy.da.SearchCursor(layer_path, ["SITE_NUM"])]