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?
enter image description here
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
-
4Have you looked at custom tool validation? It can be used to populate fields based on other fields.Barbarossa– Barbarossa2014年06月25日 15:51:44 +00:00Commented Jun 25, 2014 at 15:51
-
1You are using the old style cursor, you want to be using the new and faster searchcursor in the da module, this should resolve the speed issue.Hornbydd– Hornbydd2014年06月26日 11:43:21 +00:00Commented Jun 26, 2014 at 11:43
-
Thanks for your suggestion! I convert the table as a .csv file and use SearchCursor (arcpy.da), and it works perfectly!Energetic Codfish– Energetic Codfish2014年06月26日 23:01:24 +00:00Commented Jun 26, 2014 at 23:01
-
Older post, but i encountered a similar issue when i was building an addin. You will want to use the .da flavor of the searchcursor, and also use a data format that is more system friendly, like csv or xlsx.COCO– COCO2016年06月12日 13:23:29 +00:00Commented Jun 12, 2016 at 13:23
1 Answer 1
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.
-
1@EnergeticCodfish If this solved your problem can you click the green Accept button, please?2014年12月16日 00:17:27 +00:00Commented Dec 16, 2014 at 0:17