AnsweredAssumed Answered

Subset Selection in Python Add-in tool

Question asked by wtgeographer@gmail.com on Jan 31, 2013
Latest reply on Mar 13, 2014 by pscipione
Can anybody tell me why the second combo box (subset selection) does not become enabled in python add-in?
Here is a picture and code...

[ATTACH=CONFIG]21258[/ATTACH]

import arcpy import pythonaddins #Clear any Selections there may be on the Document before it is opened #set the layer variable to the first layer in the map document(coded inline with layer) layer = arcpy.mapping.ListLayers(arcpy.mapping.MapDocument("CURRENT"))[0] # Select the layer to clear any Current selection on the map arcpy.SelectLayerByAttribute_management(layer,"CLEAR_SELECTION") #refresh the active view of the map document arcpy.RefreshActiveView()   class Survey(object):     """Implementation for MapperTest_addin.combobox1 (ComboBox)"""     def __init__(self):         #in the initialisation of the addin         self.items = []         self.editable = True         self.enabled = True         self.dropdownWidth = 'WWWWWW'         self.width = 'WWWWWW'         #set the map document reference         mxd = arcpy.mapping.MapDocument("CURRENT")         #set the dataframe reference using the map document and the first data frame in the list         df = arcpy.mapping.ListDataFrames(mxd)[0]         #set the layer reference using the map document reference and the first layer in the list of layers         layer = arcpy.mapping.ListLayers(mxd)[0]         # check if the layer exists         if layer:             #create a column name variable for the search cursor parameters             column_Survey = "L1SURNAM"             #create a search cursor for the survey name field             sc = arcpy.SearchCursor(layer,""""L1SURNAM" <> ' '""","",column_Survey,column_Survey)             #Due to the multiple values stored in the attribute table a dictionary had to be used             #Create a dictionary             dictionary = {}             #for loop to iterate through the attribute tables getting the values for the column             for row in sc:                 #set the value as the row value in the column Survey                 val = row.getValue(column_Survey)                 #the nature of dictionaries does not allow for duplicates thus handling the redundant block numbers in the data table for use in the combobox                 dictionary[val] = val                 #create a list of items for the dictionary's unique keys to be written to             Items = []             #for loop to iterate through the keys in the dictionary             for key in dictionary.iterkeys():                 #append the key values to the list Items                 Items.append(key)                 #append the list of keys to the Survey(self) item list                 self.items.append(key)             #sort keys in ascending numeric order             self.items.sort()         #delete row variable         del row         #delete search cursor         del sc      def onSelChange(self, selection):         #set the map document reference         mxd = arcpy.mapping.MapDocument("CURRENT")         #set the dataframe reference using the map document and the first data frame in the list         df = arcpy.mapping.ListDataFrames(mxd)[0]         #set the layer reference using the map document reference and the first layer in the list of layers         layer = arcpy.mapping.ListLayers(mxd)[0]         #Use the select by attributed tool to create a new selection of the survey based on the selection in the combobox         arcpy.SelectLayerByAttribute_management(layer,"NEW_SELECTION","L1SURNAM = '" + selection + "'")         #zoom to the selected features in the dataframe         df.zoomToSelectedFeatures()         #refresh the active view         arcpy.RefreshActiveView()         #if the layer exists         if layer:             #empty the block number item list             Block.items = []             #create a variable for the block number             column_Block = "L2BLOCK"             #create a search cursor for the layer on the lot number field selecting all the values that are not an empty string             sc = arcpy.SearchCursor(layer,""""L2BLOCK" <> ' '""","",column_Block,column_Block)             #for loop to read through the values in the block number field             for row in sc:                 #append the lot number items to the block number item list                 LotNumber.items.append(row.getValue(column_Block))                 #once a selection is made the block number box becomes active                 Block.enabled = True         #delete row variable         del row         #delete rsearch cursor         del sc     def onEditChange(self, text):         #create a variable to store the text in for the selection tool         surNam = text         #set the map document reference         mxd = arcpy.mapping.MapDocument("CURRENT")         #set the dataframe reference using the map document and the first data frame in the list         df = arcpy.mapping.ListDataFrames(mxd)[0]         #set the layer reference using the map document reference and the first layer in the list of layers         layer = arcpy.mapping.ListLayers(mxd)[0]         #Selection tool used to select the values in the layer where the survey name is the value that is typed into the combo box         arcpy.SelectLayerByAttribute_management(layer,"NEW_SELECTION","L1SURNAM = '" + surNam + "'")         #Zoom to the selected features         df.zoomToSelectedFeatures()      def onFocus(self, focused):         pass     def onEnter(self):         pass     def refresh(self):         pass   class Block(object):     """Implementation for MapperTest_addin.combobox2 (ComboBox)"""     def __init__(self):         self.items = []         self.editable = True         #only activated when block number is populated         self.enabled = False         self.dropdownWidth = 'WWWWWW'         self.width = 'WWWWWW'     def onSelChange(self, selection):         blockNum = selection         #set the map document reference         mxd = arcpy.mapping.MapDocument("CURRENT")         #set the dataframe reference using the map document and the first data frame in the list         df = arcpy.mapping.ListDataFrames(mxd)[0]         #set the layer reference using the map document reference and the first layer in the list of layers         layer = arcpy.mapping.ListLayers(mxd)[0]         #select a subset from the selected fields of blocknumber         arcpy.SelectLayerByAttribute_management(layer,"SUBSET_SELECTION","L2BLOCK = '" + blockNum + "'")         df.zoomToSelectedFeatures()         arcpy.RefreshActiveView()     def onEditChange(self, text):         pass     def onFocus(self, focused):         pass     def onEnter(self):         pass     def refresh(self):         pass

Attachments

Outcomes