I am trying to make a somewhat interactive interface using python add-ins and a python toolbox.
What I currently have
- First Parameter (self.srchlist) : A Value List which holds the type of searches that can be performed.
- Second Parameter (self.srchtxt) : A GPString parameter for the user to enter the search text
What I would like to have
- As the user enters a fourth character in Second Parameter, it kicks off a arcpy.da.SearchCursor based on the selection of First Parameter.
- Have the return from the SearchCursor display as a table in a Third Parameter.
- Once the user finds the result, select a row, click OK and perform a SelectByAttribute and zoom to the selected feature.
Where I am getting stuck, can the result of a SearchCursor be returned to a parameter that looks like a table. I have looked over the parameters and there seems to be a couple of ways to get data into a tabular format but I am getting CLSID errors for Value Table and it does not load properly.
If there is a dynamic way to take a cursor and insert the field names and their respective values into a datatype="GPString" I would imagine I could find a way to make that work. Although if there was a way to have an empty table as a parameter and update the contents when Parameter 2 is altered that would be the optimal solution for my situation. Any thoughts on how this might be accomplished?
class Searches(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Searches"
self.description = ""
self.canRunInBackground = False
self.srchlist = ""
self.srchtbl = ""
self.srchtxt = ""
def getParameterInfo(self):
# First parameter
self.srchlist = arcpy.Parameter(displayName="Select Search",name="in_searches",datatype="GPString",parameterType="Required",direction="Input")
self.srchlist.filter.type = "Value List"
self.srchlist.filter.list = ['Parcel ID','Owner Name']
self.srchlist.value = self.srchlist.filter.list[0]
# Second parameter
self.srchtxt = arcpy.Parameter(displayName="Enter Search Criteria",name="in_searchestext",datatype="GPString",parameterType="Required",direction="Input")
# Third parameter
self.srchtbl = arcpy.Parameter(displayName="Results",name="out_searchestable",datatype="Value Table",parameterType="Required",direction="Ouput")
parameters = [self.srchlist, self.srchtxt, self.srchtbl]
return parameters
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
## if parameters[0].altered:
## if str(parameters[0]) == "Parcel ID":
## self.srchtbl.columns = [['PIN','OWN1','OWN2'],['String','String','String']]
## if str(parameters[0]) == "Owner Name":
## self.srchtbl.columns = [['PIN','OWN1','OWN2'],['String','String','String']]
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
return