SET_VARIABLE vROUTE {route: = select Route1 from Handholes where Route1 is not null union select Route2 from Handholes where Route2 is not null union select Route3 from Handholes where Route3 is not null} SET_VARIABLE vHANDHOLE {handhole: = select HandholeID1 from Handholes where HandholeID1 is not null and Route1 = '{vROUTE}' union select HandholeID2 from Handholes where HandholeID2 is not null and Route2 = '{vROUTE}' union select HandholeID3 from Handholes where HandholeID3 is not null and Route3 = '{vROUTE}'} FIND_SQL select * from Handholes where (Route1 = '{vROUTE}' and HandholeID1 = '{vHANDHOLE}') or (Route2 = '{vROUTE}' and HandholeID2 = '{vHANDHOLE}') or (Route3 = '{vROUTE}' and HandholeID3 = '{vHANDHOLE}')
import os, pythonaddins, sys, arcpy from arcpy import env env.workspace = r"Database Connections\prod_GilaRiver.sde" srchConn = env.workspace + "\GilaRiver.dbo." mxd = arcpy.mapping.MapDocument("CURRENT") def ClrLists(): cboGotoList2.items = [] cboGotoList2.value = "" cboGotoList2.refresh() cboGotoList2.enabled = False cboGotoList1.items = [] cboGotoList1.value = "" cboGotoList1.refresh() def PopulateCombobox1(layer,fields): global srchLyr global srchFlds1 srchLyr = layer srchFlds1 = fields print "*** def PopulateCombobox1" print "srchLyr = " + srchLyr + ", srchFlds1 = " + str(srchFlds1) ClrLists() values = [] for field in srchFlds1: print "field: " + field values = values + [row[0] for row in arcpy.da.SearchCursor(srchConn + srchLyr, (field))] uniqueValues = sorted(set(values)) for uniqueValue in uniqueValues: if uniqueValue is not None and uniqueValue != "": cboGotoList1.items.append(uniqueValue) cboGotoList1.enabled = True def PopulateCombobox2(): print "*** def PoplateCombobox2" print "srchLyr = " + srchLyr + ", srchFlds2 = " + str(srchFlds2) cboGotoList2.items = [] cboGotoList2.value = "" cboGotoList2.refresh() values = [] for field in srchFlds2: print "field: " + field values = values + [row[0] for row in arcpy.da.SearchCursor(srchConn + srchLyr, (field))] uniqueValues = sorted(set(values)) for uniqueValue in uniqueValues: if uniqueValue is not None and uniqueValue != "": cboGotoList2.items.append(uniqueValue) cboGotoList2.enabled = True def ZoomToFeature(): print "*** def ZoomToFeature" print "srchVal1: " + str(srchVal1) + ", srchFlds1: " + str(srchFlds1) + ", srchFlds2: " + str(srchFlds2) df = arcpy.mapping.ListDataFrames(mxd, mxd.activeDataFrame.name)[0] dfLyr = arcpy.mapping.ListLayers(mxd, srchLyr, df)[0] expr1 = "" print "len(srchFlds1): " + str(len(srchFlds1)) for idx, field in enumerate(srchFlds1): expr1 = expr1 + str(field) + " = '" + str(srchVal1) + "'" print "expr1(initial): " + expr1 print "idx: " + str(idx) if len(srchFlds1) > 1 and idx < (len(srchFlds1) - 1): expr1 = " or " + expr1 print "expr1(final): " + expr1 if len(srchFlds2) == 0: arcpy.SelectLayerByAttribute_management(srchLyr,"NEW_SELECTION",expr1) else: arcpy.SelectLayerByAttribute_management(srchLyr,"NEW_SELECTION",str(srchFlds1) + " = '" + str(srchVal1) + "' and " + str(srchFlds2) + " = '" + str(srchVal2) + "'") df.extent = dfLyr.getSelectedExtent(False) if srchLyr == "zEXCHANGE": df.scale = df.scale * 1.05 else: df.scale = 600 arcpy.SelectLayerByAttribute_management(srchLyr,"CLEAR_SELECTION") class GotoSubscriberE911(object): # implementation for GRTISearch_addin.btnGotoSubscriberE911 (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): global srchFlds2 srchFlds2 = [] if arcpy.Exists("zSUBSCRIBER") == True: PopulateCombobox1("zSUBSCRIBER",["E911ID"]) else: pythonaddins.MessageBox("Please add layer to use tool", "Missing Layer") class GotoSubscriberAddress(object): # implementation for GRTISearch_addin.btnGotoSubscriberAddress (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): global srchFlds2 srchFlds2 = [] if arcpy.Exists("zSUBSCRIBER") == True: PopulateCombobox1("zSUBSCRIBER",["Address"]) else: pythonaddins.MessageBox("Please add layer to use tool", "Missing Layer") class GotoCentralOffice(object): # implementation for GRTISearch_addin.btnGotoCentralOffice (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): global srchFlds2 srchFlds2 = [] if arcpy.Exists("zCENTRALOFFICE") == True: PopulateCombobox1("zCENTRALOFFICE",["Name"]) else: pythonaddins.MessageBox("Please add layer to use tool", "Missing Layer") class GotoDLC(object): # implementation for GRTISearch_addin.btnGotoDLC (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): global srchFlds2 srchFlds2 = [] if arcpy.Exists("zDLC") == True: PopulateCombobox1("zDLC",["Name"]) else: pythonaddins.MessageBox("Please add layer to use tool", "Missing Layer") class GotoExchange(object): # implementation for GRTISearch_addin.btnGotoExchange (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): global srchFlds2 srchFlds2 = [] if arcpy.Exists("zEXCHANGE") == True: PopulateCombobox1("zEXCHANGE",["Exchange"]) else: pythonaddins.MessageBox("Please add layer to use tool", "Missing Layer") class GotoHandhole(object): # implementation for GRTISearch_addin.btnGotoHandhole (Button)""" def __init__(self): self.enabled = True self.checked = False def onClick(self): global srchFlds2 srchFlds2 = ["HandholeID1","HandholeID2","HandholeID3"] if arcpy.Exists("zHANDHOLE") == True: PopulateCombobox1("zHANDHOLE",["Route1","Route2","Route3"]) else: pythonaddins.MessageBox("Please add layer to use tool", "Missing Layer") class GotoList1(object): # implementation for GRTISearch_addin.cboGotoList1 (ComboBox)""" def __init__(self): self.items = [] self.editable = True self.enabled = False self.dropdownWidth = 'WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW' self.width = 'WWWWWWWW' def onSelChange(self, selection): global srchVal1 srchVal1 = selection print "*** class cboGotoList1" print "srchVal1: " + str(srchVal1) + ", srchFlds1: " + str(srchFlds1) + ", srchFlds2: " + str(srchFlds2) if len(srchFlds2) == 0: ZoomToFeature() else: PopulateCombobox2() def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): global srchVal1 srchVal1 = cboGotoList1.value print "*** class cboGotoList1" print "srchVal1: " + str(srchVal1) + ", srchFlds1: " + str(srchFlds1) + ", srchFlds2: " + str(srchFlds2) if srchVal1 != "None": if len(srchFlds2) == 0: ZoomToFeature() else: PopulateCombobox2() def refresh(self): pass class GotoList2(object): # implementation for GRTISearch_addin.cboGotoList2 (ComboBox)""" def __init__(self): self.items = [] self.editable = True self.enabled = False self.dropdownWidth = 'WWWWWWWWWWWWWWWW' self.width = 'WWWWWWWW' def onSelChange(self, selection): srchVal2 = selection print "*** class cboGotoList2" print "srchVal2: " + str(srchVal2) + ", srchFlds2: " + srchFlds2 ZoomToFeature() def onEditChange(self, text): pass def onFocus(self, focused): pass def onEnter(self): pass def refresh(self): pass
I finally figured out the solution. Got it to work. I have layers that can be searched by a value in one field, and others by two fields, with the second value being filtered by what's selected in the first one. Each time a layer is selected to query the pick lists populate/de-populate and enable/disable as needed. But I haven't figured out how to share my Python add-in here. Is there a different place than GeoNet to share code?
ArcScripts 2.0 (as it is currently being called) will surface sometime in the near-ish future, in the interim GitHub seems to be the place
I couldn't figure out how to add the solution files here so I created a new post here Python add-in Custom Search toolbar