I'm trying to build an ArcPy tool, which will ask the user to input some information (ID, Name, Address, Zip, etc.) first. My add-in interface is shown below, and hope to implement that once the user inputs the ID, if all the other related info (Name, Address, etc.) exist in another known table, they could be shown in the following blanks at the same time, instead of letting the user type in everything.
In short, can ArcPy fill forms in the Add-in interface, not in the result window?
The validation works, but extremely slow when I run a search cursor in a .dbf which has more than 160,000 records. How can I improve the code below, or is there a better solution other than using python script tool?
It seems the form will go through the cursor again even after I fill other unrelated blanks.
import arcpy, datetime
import os
import sys
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
self.params = arcpy.GetParameterInfo()
fc = "C:\\test\\vectorDBO.dbf"
field = "PARCEL"
cursor = arcpy.SearchCursor(fc)
row = cursor.next()
n = 0
while row:
if row.getValue("PARCEL") == self.params[0].value:
self.params[1].value = row.getValue("LASTNM")
self.params[3].value = row.getValue("ADDRESS")
self.params[4].value = row.getValue("CITY")
self.params[6].value = row.getValue("ZIPCODE")
break
row = cursor.next()
def initializeParameters(self):
"""Refine the properties of a tool's parameters. This method is
called when the tool is opened."""
self.params[10].value = datetime.datetime.now()
return
def updateParameters(self):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
Best Answer
I've never used Python Addins but the interface you describe is a Script Tool. A discussion about calling Script tools from Addins is found here. As @Barbarossa comments above you can use tool validation to populate the parameters. Unless there is a specific reason for creating a Python Addin I would probably stick to creating a Python Script Tool.