class MAPSearch_item(object): """Implementation for MAPSearch.item (ComboBox)""" def __init__(self): self.items = ["Stores", "Customers"] self.editable = False self.enabled = true self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global SearchItem SearchItem = selection global SearchLayer if selection == "Stores": try: SearchLayer = arcpy.mapping.Layer(r"C:applicationDeployment\\" + \ "MAPS 1.5\Layers\Stores.lyr") except Exception as e: pythonaddins.MessageBox("\ An unexpected error occured. Please contact the GIS Manager with the \ following error message: \ " + e.message, "ERROR", 0) return elif selection == "Customers": try: SearchLayer = arcpy.mapping.Layer(r"C:applicationDeployment\\" + \ "MAPS 1.5\Layers\Customers.lyr") except Exception as e: pythonaddins.MessageBox("\ An unexpected error occured. Please contact the GIS Manager with the \ following error message: \ " + e.message, "ERROR", 0) return else: pythonaddins.MessageBox("Item is not a valid selection.", "ERROR", 0) return def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): self.refresh() class MAPSearch_field(object): """Implementation for MAPSearch.field (ComboBox)""" def __init__(self): self.editable = False self.enabled = True self.dropdownWidth = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' self.width = 'XXXXXXXXXXXXXXXXXXXXXXXXXX' def onSelChange(self, selection): global SearchField # The question is, once the user makes a selection, the selection is actually an aliasName for a field as # specified in the onFocus function. So 'selection' returns an aliasName. How do I resolve the given aliasName # back to the actual field in order to complete the below Query? SearchField = selection global SearchSet try: SearchSet = set([r[0] for r in arcpy.da.SearchCursor(SearchLayer, SearchField)]) except Exception as e: pythonaddins.MessageBox("\ An unexpected error occured. Please contact the GIS Manager with the \ following error message: \ " + e.message, "ERROR", 0) return def onEditChange(self, text): pass def onFocus(self, focused): # When user gives focus to combobox, dynamically populate the combobox with the aliasName # of every 'Text' field in the 'SearchLayer' established in the 'MAPSearch_item' self.items = [] for Field in arcpy.ListFields(SearchLayer, "*", "TEXT"): self.items.append(Field.aliasName) def onEnter(self): pass def refresh(self): self.refresh()
Solved! Go to Solution.
dict = {f.aliasName: f.name for f in arcpy.ListFields(layer)}
dict = {f.aliasName: f.name for f in arcpy.ListFields(layer)}
You can make a reference dictionary with the alias name as the key.dict = {f.aliasName: f.name for f in arcpy.ListFields(layer)}