AnsweredAssumed Answered

Python add in use result from one class in another

Question asked by dmetzler on Jun 3, 2015

Hello,

I am attempting my very first python add in. what I would like it to do is look at a feature class, look through the town field. when the user selects a town I want the next combo box to populate with the LABELTEXT field with all of the values in that town and when a LABELTEXT is selected zoom to that bad boy.

 

I dont know how to get the town return into the ComboClass2 class or build the query to filter based on the town result

 

class ComboBoxClass1(object):
    """Implementation for addin2_addin.combobox (ComboBox)"""


    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWWWWWWWWWW'
        self.width = 'WWWWWWWWWWWWWWWW'


    def onSelChange(self, selection):
        layer = arcpy.mapping.ListLayers(mxd, "block_cards", df)[0]
        a = arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "town = '" + selection + "'")
        return a
        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, "block_cards", df)[0]
        arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
        self.items = []
        values = [row[0] for row in arcpy.da.SearchCursor(layer, ["town"])]
        for uniqueVal in sorted(set(values)):
            self.items.append(uniqueVal)


class ComboBoxClass2(object):
    """Implementation for addin2_addin.combobox (ComboBox)"""


    def __init__(self):
        self.editable = True
        self.enabled = True
        self.dropdownWidth = 'WWWWWW'
        self.width = 'WWWWWW'


    def onSelChange(self, selection):
        layer = arcpy.mapping.ListLayers(mxd, "block_cards", df)[0]
        arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION", "town = '" + ComboBoxClass1.onSelChange() + "' AND LABELTEXT = '" + 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, "block_cards", df)[0]
        arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
        self.items = []
        values = [row[0] for row in arcpy.da.SearchCursor(layer, ["LABELTEXT"])]
        for uniqueVal in sorted(set(values)):
            self.items.append(uniqueVal)

Outcomes