AnsweredAssumed Answered

Update Cursor Tool Returing Error

Question asked by rralbritton1981 on Mar 28, 2013
Latest reply on Mar 28, 2013 by rralbritton1981
I've written a tool that loops through a parcel file, counts how many buffers intersect a parcel record within that file than updates an attribute field in the parcel layer with this number. The tool runs fine until it gets to the final record in the parcel layer then I get an error message that says

<type 'exceptions.NameError'>: name 'line' is not defined Failed to execute (RCW 3 Mile).



If I open up the layers attribute table, all the fields have been correctly updated so I don't understand why this error is occurring. Since the tool is part of a larger model I need to understand why this is happening sot the model can proceed forward.

I also tried running the tool independently (outside of modelbuilder) with the same results.

This is the code in the tool:

 #Select out each parcel record one by one and evalauate how many cluster buffers intersect with that parcel. #Update Parcel Attribute Table field three_mi with the # of buffers that intersect that parcel  SelectedParcelsFL=arcpy.GetParameterAsText(0) CbuffersFL=arcpy.GetParameterAsText(1)  #make sure that no records are currently selected in either slected parclesFL or cBuffersFL arcpy.AddMessage("Clearing selected parcel selections\n") arcpy.SelectLayerByAttribute_management(SelectedParcelsFL,"CLEAR_SELECTION") arcpy.AddMessage("Clearing selected buffer selections\n") arcpy.SelectLayerByAttribute_management(CbuffersFL,"CLEAR_SELECTION")  #Now begin 3-mile disperal buffer count print "updating parcels table with the number of 3-mile RCW dispersal buffers that intersect each parcel" arcpy.AddMessage("updating parcels table with the number of 3-mile RCW dispersal buffers that intersect each parcel\n")  for parcel in range(0,1092):     FID = "FID=%s" % (parcel)     arcpy.SelectLayerByAttribute_management(SelectedParcelsFL,"NEW_SELECTION",FID)     arcpy.SelectLayerByLocation_management(CbuffersFL,"INTERSECT",SelectedParcelsFL)     bufferCount = int(arcpy.GetCount_management(CbuffersFL).getOutput(0))     arcpy.AddMessage(str(FID)+" has "+str(bufferCount)+" RCW 3-mile dispersal buffers that intersect with it.")      #Update the three_mi field      uc=arcpy.UpdateCursor(SelectedParcelsFL)     for line in uc:         line.three_mi = bufferCount         uc.updateRow(line) #Actually changes the table values to buffer count     del line, uc          arcpy.SelectLayerByAttribute_management(SelectedParcelsFL,"CLEAR_SELECTION") print "updating parcels table with the number of 3-mile RCW dispersal buffers that intersect each parcel COMPLETED" arcpy.AddMessage("updating parcels table with the number of 3-mile RCW dispersal buffers that intersect each parcel COMPLETED")

Outcomes