I'm trying to create a distinct list of values in my Python addin combo box drop down list; i already have the script that actually shows all the values of the field appended to my combo box drop down. What i intend to achieve with this is to have a list of distinct values on my drop down - see my code below;
def __init__(self):
OBJECTID = []
for row in arcpy.SearchCursor("BldForm"):
OBJECTID.append(row.Combo)
self.items = sorted(OBJECTID)
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWW'
def onSelChange(self, selection):
mxd = arcpy.mapping.MapDocument("Current")
for df in arcpy.mapping.ListDataFrames(mxd):
if df.name == "Layers":
dfmain = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
OBJECTID = []
for row in arcpy.SearchCursor("BldForm"):
OBJECTID.append(row.Combo)I'll kindly appreciate your help on this.
Solved! Go to Solution.
Two suggestions:
with arcpy.da.SearchCursor("BldForm", ['Combo']) as rows: OBJECTID = sorted(set([row[0] for row in rows]))
Two suggestions:
with arcpy.da.SearchCursor("BldForm", ['Combo']) as rows: OBJECTID = sorted(set([row[0] for row in rows]))
Another option and many other nice snippets Some Python Snippets
Thanks for saving my day!!!!