I'm using this thread as the base for my python addin toolbar.How to populate Add-In Combo Box with attributes
I was wondering if it was possible to limit the field unique values to whats in the map extent. There are thousands of unique values which doesn't take long to populate the combobox but to help the end user I would like to limit those to what's in the map extent.
Here's my python code so far. You select the specific layer, then it sorts and pushes the unique values to a combobox. Once you select a feature from the drop down, it selects and zooms to that feature.
import arcpy
import pythonaddins
class leveeLayerListSelector(object):
"""Implementation for LeveeSearch_addin.comboboxLayerList (ComboBox)"""
def __init__(self):
self.items = []
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWWWWWWWWWWWWWWWW'
self.width = 'WWWWWW'
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
def onSelChange(self, selection):
global fc
fc = arcpy.mapping.ListLayers(self.mxd, selection)[0]
class leveeSystemSelector(object):
"""Implementation for LeveeSearch_addin.comboboxLeveeSystem (ComboBox)"""
def __init__(self):
self.items = []
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW'
self.width = 'WWWWWW'
def onSelChange(self, selection):
self.mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(self.mxd, "Layers") [0]
arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "System_Name = '" + selection + "'")
df.zoomToSelectedFeatures()
arcpy.RefreshActiveView()
def onEditChange(self, text):
pass
def onFocus(self, focused):
self.mxd = arcpy.mapping.MapDocument('current')
global layer
layer = arcpy.mapping.ListLayers(self.mxd, fc)[0]
self.items = []
values = [row[0] for row in arcpy.da.SearchCursor(layer, ["System_Name"])]
for uniqueVal in sorted(set(values)):
self.items.append(uniqueVal)
def onEnter(self):
pass
def refresh(self):
pass-Steven