# Import arcpy and date time module import arcpy import datetime # Local variables: today = datetime.date.today() mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] parcels = arcpy.mapping.ListLayers(mxd, "Parcels", df) [0] # Geting user input for project name, status, type, submital date and planner name ProjectName = arcpy.GetParameterAsText(0) ProjStatus = arcpy.GetParameterAsText(2) SubmitDate = arcpy.GetParameterAsText(1) DevelopeType = arcpy.GetParameterAsText(3) PlannerName = arcpy.GetParameterAsText(4) PlanningProjectTracking = "C:\\David Projects\\Planning Project Tracking\\PythonProjectTracking.mdb\\PlanningProjectTracking" whereClause = "[ProjectName] = '{0}'".format(ProjectName) #Used update cursor to create update project tracking records. Ucursor = arcpy.da.UpdateCursor(PlanningProjectTracking, whereClause, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"]) for row in Ucursor: row.setValue (ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today) Ucursor.updateRow(row) arcpy.RefreshActiveView()
Solved! Go to Solution.
Ucursor = arcpy.da.UpdateCursor(PlanningProjectTracking, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"], whereClause) for row in Ucursor: Ucursor.updateRow([ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today])
Ucursor = arcpy.da.UpdateCursor(PlanningProjectTracking, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"], whereClause) for row in Ucursor: Ucursor.updateRow([ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today])
You've mixed up the argument order, the list of fields goes before the where clause. In addition, you're mixing up your cursor models. There's no row.setValue in da.UpdateCursor.Ucursor = arcpy.da.UpdateCursor(PlanningProjectTracking, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"], whereClause) for row in Ucursor: Ucursor.updateRow([ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today])
Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"])
arcpy.da.UpdateCursor and arcpy.UpdateCursor are two different things, your script looks like it's creating an arcpy.da.UpdateCursor but treating it like an arcpy.UpdateCursor. You may be able to get away with your original script just by doing this:Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"])
Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause, "", ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"])for row in Ucursor: row.setValue (ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today) Ucursor.updateRow(row) arcpy.RefreshActiveView()
Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause, "", ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"])for row in Ucursor: for fieldname, value in [('PROJECTNAME', ProjectName), ('STATUS', ProjStatus), ('SUBMITTALDATE', SubmitDate), ('DEVELOPEMENTTYPE', DevelopeType), ('PLANNER', PlannerName), ('EDITDATE', today)]: row.setValue(fieldname, value) Ucursor.updateRow(row)
Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause, "", ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"])for row in Ucursor: for fieldname, value in [('PROJECTNAME', ProjectName), ('STATUS', ProjStatus), ('SUBMITTALDATE', SubmitDate), ('DEVELOPEMENTTYPE', DevelopeType), ('PLANNER', PlannerName), ('EDITDATE', today)]: row.setValue(fieldname, value) Ucursor.updateRow(row)
Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause, "", ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"])for row in Ucursor:
with arcpy.da.UpdateCursor(PlanningProjectTracking, ["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"], whereClause) as Ucursor: for row in Ucursor: Ucursor.updateRow([ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today])
Ucursor = arcpy.UpdateCursor(PlanningProjectTracking, whereClause) for row in Ucursor: for fieldname, value in (('PROJECTNAME', ProjectName), ('STATUS', ProjStatus), ('SUBMITTALDATE', SubmitDate), ('DEVELOPEMENTTYPE', DevelopeType), ('PLANNER', PlannerName), ('EDITDATE', today)): row.setValue(fieldname, value) Ucursor.updateRow(row)
SubmitDate = arcpy.GetParameterAsText(1)
from datetime import datetime submitDate = '24-9-2013' dateObj = datetime.strptime(submitDate,'%d-%m-%Y') submitDate = '9/24/2013' dateObj = datetime.strptime(submitDate,'%m/%d/%Y')
SubmitDate = arcpy.GetParameter(1)
# Import arcpy and date time module import arcpy import datetime # Local variables: today = datetime.date.today() mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0] ProjectTracking = arcpy.mapping.ListLayers(mxd, "PlanningProjectTracking", df) [0] # Geting user input for project name, status, type, submital date and planner name ProjectName = arcpy.GetParameterAsText(0) ProjStatus = arcpy.GetParameterAsText(2) SubmitDate = arcpy.GetParameterAsText(1) DevelopeType = arcpy.GetParameterAsText(3) PlannerName = arcpy.GetParameterAsText(4) #Set variable to hold SQL statement to query out project to update whereClause = "[ProjectName] = '{0}'".format(ProjectName) #Used update cursor to create update project tracking records. Ucursor = arcpy.da.UpdateCursor(ProjectTracking,["PROJECTNAME","STATUS","SUBMITTALDATE","DEVELOPEMENTTYPE","PLANNER","EDITDATE"],whereClause) for row in Ucursor: irow = (ProjectName,ProjStatus,SubmitDate,DevelopeType,PlannerName,today) Ucursor.updateRow(irow) arcpy.RefreshActiveView()