Ok got it fixed. Your field names being different from mine definitely caused some problems. Also, the range and township fields were of float type, which was causing problems as well. I copied those fields as short ints to fix the problem. This now works perfectly for me. Here is the solution, all that you will need to change is the path to the Owner_Surface feature class.
import arcpy, sys, traceback
sections = r'C:\TESTING\TestData\TestData.gdb\Owner_Surface'
def Quads(sections):
urows = arcpy.UpdateCursor(sections)
for row in urows:
if row.quad == 1:
row.setValue('QUAD_LBL','N W')
urows.updateRow(row)
elif row.quad == 2:
row.setValue('QUAD_LBL','N E')
urows.updateRow(row)
elif row.quad == 3:
row.setValue('QUAD_LBL','S W')
urows.updateRow(row)
elif row.quad == 4:
row.setValue('QUAD_LBL','S E')
urows.updateRow(row)
del row, urows
try:
# add fields
arcpy.AddField_management(sections, 'QUAD_LBL', 'TEXT','','', 3)
arcpy.AddField_management(sections, 'LABEL', 'TEXT','','', 15)
arcpy.AddField_management(sections, 'townshp2', 'SHORT')
arcpy.AddField_management(sections, 'range2', 'SHORT')
# update new field for quads label
Quads(sections)
# Generate full label field
urows = arcpy.UpdateCursor(sections)
for row in urows:
row.townshp2 = row.township
row.range2 = row.range
quad = row.QUAD_LBL # splits by space in new quad field
twp = row.townshp2
rng = row.range2
sec = row.section_
row.LABEL = 'T%s%s R%s%s Sec%s' %(twp, quad.split(' ')[0], rng, quad.split(' ')[-1], sec)
urows.updateRow(row)
del row, urows
print 'Done'
except:
# Get the traceback object
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
# Concatenate information together concerning the error into a message string
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
# Return python error messages for use in script tool or Python Window
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
# Print Python error messages for use in Python / Python Window
print pymsg + "\n"
print msgs
I also used a print statement to show the labels being populated:T21S R7E Sec36T30S R12W Sec34T14N R2E Sec18T2N R25W Sec2Done