I am trying to make a somewhat interactive interface using python add-ins and a python toolbox.
What I currently have
What I would like to have
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
unfortunately you cant create a table within the UI of the GP tool. You could possibly try that using an external UI module like PyQT. Another option maybe to fill out a combo box
Sorry I'm late to the discussion - but others who are searching for help on this may still find my reply useful. Matthew is wrong, this can be done. I believe you were almost there, you just needed to give the value table structure in the definition, in GetParameterInfo(). By the time you get to updateParameters(), it's already established the structure (none) and can't modify it. This is a good example of how to do it: https://gis.stackexchange.com/questions/123273/set-default-values-for-value-table-in-python-toolbox-...