I need help on the Update Cursor function

6952
42
Jump to solution
08-23-2012 07:27 AM
OLANIYANOLAKUNLE
Frequent Contributor
Im trying to update a field called "GENERATED" with an attribute called "GENERATED" every time i autogenerate a map, i constructed this script and it is not updating and i didnt see an error(s)

rows = arcpy.UpdateCursor("Parcels",'[OBJECTID] = "1"')
row = rows.next()
while row:
    row.setvalue(GENERATED, GENERATED)
    rows.updateRow(row)
    row = rows.next()

Please any suggestions. Im desperate. Thanks
Tags (2)
0 Kudos
42 Replies
nimitz
by
Frequent Contributor
For SAG's (American slang), here's the v10.1 equivalent using the new "data access" update cursor syntax:



OK, for us noobs, what is SAG an acronym for? Screen Actor's Guild? j/k 🙂
0 Kudos
OLANIYANOLAKUNLE
Frequent Contributor
There are helpful examples in the help for SearchCursor.

2. For a reason i don't know the script

arcpy.MakeFeatureLayer_management("Parcels", "tLyr", '"TDP_Status" = \'GENERATED\'')
count = int(arcpy.GetCount_management("tLyr").getOutput(0))
if count == 0: 
    arcpy.AddMessage("TDP already generated")
else:
    arcpy.Buffer_analysis("Parcels", "ClipFeature", "12.5 meters", "FULL", "ROUND", "LIST")


Continues with the buffer process even if the count is o or 1. Do you know why?


This shouldn't happen if your indents are correct as above. I would test your script by printing a test message (arcpy.AddMessage("Count is: " + str(count)).

The script still continues with the buffer analysis; can you help me with an arcpy script that can end/stop the process if the count condition is true?
Thanks for your information on the pdf naming convention.... I got it. Thanks man Thanks
0 Kudos
OLANIYANOLAKUNLE
Frequent Contributor
I have issues with dropping my pdf output in the specified destination output folder from my code below, it does create the pdf output though, but never drops it in the specified destination folder

fc = "Parcels"
field = "Block_No"
cursor = arcpy.SearchCursor(fc)
for row in cursor:
    row.getValue(field)
val = row.getValue(field)
field = "Plot_No"
cursor = arcpy.SearchCursor(fc)
for row in cursor:
    row.getValue(field)
val2 = row.getValue(field)
outName = "Block" + str(val) + "Plot_" + str(val2)
outName1 = str(val) + "Plot_" + str(val2) + ".pdf"
arcpy.CreateFolder_management("C:\GIS",outName)
arcpy.mapping.ExportToPDF(mxd,"C:\GIS\outName\outName1)


Any suggestions? Thanks
0 Kudos