Select to view content in your preferred language

Python script to enter String & Dates in existing fields

1437
12
07-19-2013 10:44 AM
JacobDrvar
Emerging Contributor
All,

I am attempting to write a Python Script that selects a record in the attribute table, zooms to the selected feature, and prompts the user to enter their name, date created, and date modified.  The name, date created, and date modified fields already exist in the attribute table.  The name field is a string type, and the date fields are date types.  I have the first part of the script written, it prompts the user to enter a RENUM value, which selects a record in the Parcels attribute table, and zooms to the selected feature.  How would I get the script to prompt the user to enter their name, date created, and date modified?  Then, have the information they enter stored in the attribute table?  I am going to have the users run the script from ArcToolbox.   Any suggestions would be welcomed.  Thanks.  What I have so far is displayed below:

#Import
import arcpy

#Variables
Parcels = arcpy.GetParameterAsText(0)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
lyr = arcpy.mapping.ListLayers(mxd, "Parcels", df)[0]
arcpy.AddMessage(lyr.name)

#Logic
try:
 whereClause = "RENUM = "+Parcels+""
 arcpy.SelectLayerByAttribute_management(lyr, "NEW_SELECTION", whereClause)
 df.extent = lyr.getSelectedExtent()
 df.scale = df.scale*1.1

except:
 print arcpy.GetMessages()
Tags (2)
0 Kudos
12 Replies
JacobDrvar
Emerging Contributor
The pass function was included in the initial Python_addin.py. 
import arcpy
import pythonaddins

class ParcelSearch(object):
    """Implementation for Python_addin.btn1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pass


I removed the pass function and the result was still the same.

If I used the SelectLayerByAttribute_management in my initial script, should the Python_addin use the same function?  Since, the Python_addin I am running calls for the ZoomtoSelectedFeatures?
0 Kudos
JamesCrandall
MVP Alum
The pass function was included in the initial Python_addin.py. 
import arcpy
import pythonaddins

class ParcelSearch(object):
    """Implementation for Python_addin.btn1 (Button)"""
    def __init__(self):
        self.enabled = True
        self.checked = False
    def onClick(self):
        pass


I removed the pass function and the result was still the same.

If I used the SelectLayerByAttribute_management in my initial script, should the Python_addin use the same function?  Since, the Python_addin I am running calls for the ZoomtoSelectedFeatures?


What I was suggesting was for you keep all of the code you had for the OnClick event, but simply just remove the pass argument at the bottom.  That is all. 

I know it automatically has it in there for each method/def when you generate the add-in for the first time.  It is up to you to determine which event to use, add the appropriate code and get the add-in installed. 

It is going to be very difficult for me to work thru the rest as there are so many little things to get done on the add-in --- you might have to rebuild and re-install it after you complete edits.  I really don't know why it is not zooming to selected and is something you might have to trial-and-error your way through it.
0 Kudos
JacobDrvar
Emerging Contributor
James, thanks for all of your help.

I believe the button works as designed.  I am able to select a feature manually and then click the button and it goes right to the feature.  But, the original script calls for a RENUM value to be entered and that Parcel is selected.  Then, the script zooms to the feature.  Is it possible for a button to open user prompt to enter a string?  Thanks.
0 Kudos