8

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
asked Jun 25, 2014 at 15:39
4
  • 4
    Have you looked at custom tool validation? It can be used to populate fields based on other fields. Commented Jun 25, 2014 at 15:51
  • 1
    You 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. Commented 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! Commented 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. Commented Jun 12, 2016 at 13:23

1 Answer 1

4

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.

answered Jun 25, 2014 at 15:58
1
  • 1
    @EnergeticCodfish If this solved your problem can you click the green Accept button, please? Commented Dec 16, 2014 at 0:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.