#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()
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()
One pattern that may work is to implement a Python Add-In that allows for some user interaction, opens another Toolbox dialog that accepts the Name and date parameters and peform the update to the attribute table of ths selected features.
I know that is a very general outline, but this is something that we have done and it works fine.
pythonaddins.GPToolDialog(r'C:\Documents\MyToolbox.tbx', 'AttributeEditor')"""
Thanks. I will need to read up on Python add-ins. With the add-in, will I still need to figure out the scripting part? Or will the add-in allow a GUI?
# Implementation of OnClick method of Button's class def onClick(self): # Get the current map document and the first data frame. mxd = arcpy.mapping.MapDocument('current') df = arcpy.mapping.ListDataFrames(mxd)[0] # Call the zoomToSelectedFeatures() method of the data frame class df.zoomToSelectedFeatures()
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): #Implementation of OnClick method of Button's class def onClick(self): #Get the current map document and the first data frame. mxd = arcpy.mapping.MapDocument('current') df = arcpy.mapping.ListDataFrames(mxd)[0] #Call the zoomToSelectedFeatures() method of the data frame class df.zoomToSelectedFeatures() pass
# Implementation of OnClick method of Button's class def onClick(self): # Get the current map document and the first data frame. mxd = arcpy.mapping.MapDocument('current') df = arcpy.mapping.ListDataFrames(mxd)[0] # Call the zoomToSelectedFeatures() method of the data frame class df.zoomToSelectedFeatures()
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): #Get the current map document and the first data frame. mxd = arcpy.mapping.MapDocument('current') df = arcpy.mapping.ListDataFrames(mxd)[0] #Call the zoomToSelectedFeatures() method of the data frame class df.zoomToSelectedFeatures() pass