values = [row[0] for row in arcpy.da.SearchCursor(layer, ["SampleYear"])] for uniqueVal in sorted(set(values)): self.items.append(uniqueVal)
with arcpy.da.SearchCursor(layer, ["SampleYear"]) as cursor: for row in cursor: self.items.append(row[0])
class WODate(object): """Implementation for woToolkit_addin.combobox_3 (ComboBox)""" def __init__(self): self.items = ["05/02/2010", "04/20/2011", "05/20/2012", "05/20/2013", "01/20/2014"] self.editable = False self.enabled = True self.dropdownWidth = 'WWWWWWWWWWW' self.width = 'WWWWWWWWWWW' def onSelChange(self, selection): pass def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass
Amazing! I got it to work. What a happy camper I am right now!One little tweak would be nice though.... At this point, when the user selects a year, it works perfectly. BUT - the other years that were available before all disappear. For instance, a particular station has the following years of data: 2009, 2010, 2011. When you select 2009, the other years (2010 and 2011) are no longer displayed in the combo box.Is there a way upon selection to keep these other years still displayed? Thanks guys!Katie
import arcpy import pythonaddins class ComboBoxClass1(object): """Implementation for UserData_addin.combobox (ComboBox)""" def __init__(self): self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' def onSelChange(self, selection): layer = r"C:\temp\python\test.gdb\Stream_Temperatures" arcpy.MakeFeatureLayer_management(layer, "Selection") arcpy.SelectLayerByAttribute_management("Selection", "NEW_SELECTION", "SampleYear = '" + selection + "'") arcpy.RefreshActiveView() def onFocus(self, focused): layer = r"C:\temp\python\test.gdb\Stream_Temperatures" self.items = [] values = [row[0] for row in arcpy.da.SearchCursor(layer, ["SampleYear"])] for uniqueVal in sorted(set(values)): self.items.append(uniqueVal)
import arcpy import pythonaddins class ComboBoxClass1(object): """Implementation for UserData_addin.combobox (ComboBox)""" def __init__(self): self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' def onSelChange(self, selection): self.mxd = arcpy.mapping.MapDocument('current') layer2 = arcpy.mapping.ListLayers(self.mxd, "a dummy layer")[0] arcpy.SelectLayerByAttribute_management(layer2, "NEW_SELECTION", "NAME = " + selection) arcpy.RefreshActiveView() def onFocus(self, focused): self.mxd = arcpy.mapping.MapDocument('current') layer = arcpy.mapping.ListLayers(self.mxd, "Stream_Temperatures")[0] self.items = [] values = [row[0] for row in arcpy.da.SearchCursor(layer, ["SampleYear"])] for uniqueVal in sorted(set(values)): self.items.append(uniqueVal)
import arcpy import pythonaddins class ComboBoxClass1(object): """Implementation for UserData_addin.combobox (ComboBox)""" def __init__(self): self.editable = True self.enabled = True self.dropdownWidth = 'WWWWWW' self.width = 'WWWWWW' def onSelChange(self, selection): arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "NAME = " + selection) arcpy.RefreshActiveView() def onFocus(self, focused): self.mxd = arcpy.mapping.MapDocument('current') global layer layer = arcpy.mapping.ListLayers(self.mxd, "Stream_Temperatures")[0] self.items = [] with arcpy.da.SearchCursor(layer, ["SampleYear"]) as cursor: for row in cursor: self.items.append(row[0])
arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "NAME = '" + selection + "'")
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.