Python script to enter name string

1720
14
Jump to solution
07-23-2013 05:26 AM
JacobDrvar
New Contributor II
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. The name field already exists in the attribute table as a string type. How would I get the script to prompt the user to enter their name?Then, have the information they enter stored in the attribute table? I am going to have the users run the script from ArcToolbox.  I have tried the python addin to toolbar/button.  But, was unable to prompt the user to enter their name or zoom to selected feature without manually selecting the feature.

import arcpy  #Variables Parcels = arcpy.GetParameterAsText(0) arcpy.AddMessage(Parcels)  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
14 Replies
JacobDrvar
New Contributor II
James,

If I create a toolbar with one button, how can I add more buttons later?

Thanks.
0 Kudos
JacobDrvar
New Contributor II
James,

After much frustration, I was finally able to convert some of my tools to buttons.  Back, to the initial part of my search.  Can you provide an example string that would ask the user to provide their name?  I would like to have the value entered directly into a field in the attribute table.  Or at least point in the correct direction with which function to use.

Thanks again.
0 Kudos
JamesCrandall
MVP Frequent Contributor
James,

After much frustration, I was finally able to convert some of my tools to buttons.  Back, to the initial part of my search.  Can you provide an example string that would ask the user to provide their name?  I would like to have the value entered directly into a field in the attribute table.  Or at least point in the correct direction with which function to use.

Thanks again.


So, if your Add-In successfully launches/opens the correct BCPAO.tbx component...

In your "NameDate" BCPAO.tbx Toolbox, add a new paramter and set it as String.

At the top of this NameDate.py, set a variable to this parameter:

 inputName = arcpy.GetParameter(0) 


Now you can use this variable in an updateCursor on your set of selected features (that's a whole other thread! 🙂
0 Kudos
JacobDrvar
New Contributor II
James, you are the man. You deserve a nice cold beer.  I greatly appreciate all of your guidance.
0 Kudos
JamesCrandall
MVP Frequent Contributor
James, you are the man. You deserve a nice cold beer.  I greatly appreciate all of your guidance.


BCPAO -- Is that acronym for Broward Co Property Appraiser Office?  If so, you can send the beer up to west palm beach just north of ya 🙂

Glad to help.
j
0 Kudos