Select to view content in your preferred language

10.2 Arcpy comboboxclass addin simple question

3833
10
Jump to solution
03-12-2014 11:04 AM
jasongraham
Regular Contributor
Hopefully this is a simple question,  what variable is used to get the selection from this combo box?  ie how do I use this in later code.  I am not finding any good resources for arcpy addins.

class ComboBoxClass4(object):     """Implementation for MTR_addin.combobox (ComboBox)"""     def __init__(self):         self.value = "S"           self.items = ("C", "F", "K", "S", "U")          self.editable = True         self.enabled = True         self.dropdownWidth = 'WWW'         self.width = 'WWW'     def onSelChange(self, selection):         pass     def onEditChange(self, text):         pass     def onFocus(self, focused):         pass     def onEnter(self):         pass     def refresh(self):         pass
Tags (2)
0 Kudos
10 Replies
jasongraham
Regular Contributor
And remember when you access your combobox you need to first have assign it properties through the class level self variables. You might be missing this part in your combobox class.

    def onSelChange(self, selection):
        self.sel = selection

Then get the selection in your other classes like this.
combobox.sel


Awesome, I got it to work!  The whole code works great now, thanks for the help.  How about a bonus round?

This is just a portion of the code, with this I populate the combobox with only unique values from the attributes, I want it sorted but something isn't working there, any ideas?

Twp = []
for row in arcpy.SearchCursor("X:\JasonGraham\Landstatus\Data\ls2014.gdb\BaseData\Townships"):
    Twp.append(row.TWP_NUMC)

class ComboBoxClass5(object): #Collect Township from list of unique values gathered from the layer
    """Implementation for MTR_addin.combobox_1 (ComboBox)"""
    def __init__(self):
        self.value = "000"
        self.items = sorted(Twp)
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWW'
        self.width = 'WWWW'
    def onSelChange(self, selection):
        self.sel = selection   
        #global valName
        #val = (self.items, selection)[1]
        #valName = str(val)
    def onEditChange(self, text):
        pass
    def onFocus(self, focused):#show only unique values
        if focused:
            values = sorted(Twp)
            uniqueValues = set(values)
            self.items = []
            for uniqueValue in uniqueValues:
                self.items.append(uniqueValue)
    def onEnter(self):
        pass
    def refresh(self):
        pass
0 Kudos