import arcpy from arcpy import env arcpy.AddMessage('Identifying parameters') stand = arcpy.GetParameterAsText(0) #stand polygon data sid = arcpy.GetParameterAsText(1) #unique stand identifier text field from stand layer pts = arcpy.GetParameterAsText(2) #plot points data p_sid = arcpy.GetParameterAsText(3) #unique stand identifier text field from point layer arcpy.AddMessage('Parameters identified.') env.workspace = pts #adds each SID to a list and looks for repeats of an SID arcpy.AddMessage('Identifying stands...') cursor1 = arcpy.da.SearchCursor(stand, [sid]) list1 = [] t = 0 for row in cursor1: global t step1 = str(row) step2 = step1.split("'")[1] if list1.count(str(step2))==0: list1.append(step2) t+=1 if t == 1: arcpy.AddMessage("Identified "+str(t)+" stand...") else: arcpy.AddMessage("Identified "+str(t)+" stands...") else: arcpy.AddMessage('!!!!Error: Stand ID (SID) "'+str(step2)+'" occurs '+str(list1.count(step2)+1)+' times!!!!') import sys sys.exit(0) del cursor1 #For each SID, selects points within the stand and updates the SID of those points arcpy.AddMessage('Assigning stand ID (SID) to points...') if len(list1) > 0: for row in list1: arcpy.SelectLayerByAttribute_management(stand, "NEW_SELECTION", str(sid)+"='"+str(row)+"'") arcpy.SelectLayerByLocation_management(pts, "WITHIN", stand,) arcpy.CalculateField_management(pts, p_sid, '"'+str(row)+'"', "PYTHON") arcpy.AddMessage('Flagging points outside of stands...') arcpy.SelectLayerByAttribute_management(stand, "NEW_SELECTION", '"OBJECTID" >= 0') arcpy.SelectLayerByAttribute_management(pts, "NEW_SELECTION", '"OBJECTID" >= 0') arcpy.SelectLayerByLocation_management(pts, "WITHIN", stand, "", "REMOVE_FROM_SELECTION") arcpy.CalculateField_management(pts, p_sid, '"FLAGGED_" + !'+str(p_sid)+'!', "PYTHON") arcpy.SelectLayerByAttribute_management(pts, "NEW_SELECTION", '"OBJECTID" < 0') arcpy.SelectLayerByAttribute_management(stand, "NEW_SELECTION", '"OBJECTID" < 0') else: arcpy.AddMessage('Issue...')Solved! Go to Solution.
Have you tried
arcpy.env.overwriteOutput = True
?
Put that at the beginning of the code and you'll overwrite the data you've already written with new or the same values.