I have looked through the other topic similar to this and they just don't seem to have exactly what I am looking for. I have a feature class 'AGM' that I want to update a field in based on the AGMs location to an LSD (which is also a feature class). The LSD has an ID field that I want to use as the field in the AGM.
My script thus far will update the field with the ID of the next LSD, it keeps cycling through the LSD and just putting whichever ID it is on before I manually stop it in the field. (seems the select layer by location is not working the way I had hoped)
#insert a new field (LSD) into the AGM shapefile, locate which LSD the AGM belongs to and update the new LSD field with the LSD ID #import modules import arcpy #set environment #set up workspace variable as user input wsp = arcpy.GetParameter (0) #arcpy.env.overwrieOutput = True #set up variables for the AGM location, the grid (LSD) location as user input agm = arcpy.GetParameter (1) grid = arcpy.GetParameter (2) #make both shapefiles a layer arcpy.MakeFeatureLayer_management (agm, "AGM") arcpy.MakeFeatureLayer_management (grid, "LSD") #create new field in AGM shapefile (LSD) arcpy.AddField_management ("AGM", "LSD", "TEXT", field_length = 40) #create search cursor for LSD cursor_LSD = arcpy.da.SearchCursor ("LSD", ["ID"]) #for each row in the LSD layer search for the ID for row_LSD in cursor_LSD: #Select the LSD ID that contains an AGM arcpy.SelectLayerByLocation_management ("LSD", "CONTAINS", "AGM") #create an update cursor to update the AM with the ID of the LSD that contains it cursor_AGM = arcpy.da.UpdateCursor ("AGM", ["LSD"]) #for the rows in the AGM update the LSD field with the ID of the LSD that contains it for row_AGM in cursor_AGM: row_AGM = row_LSD  cursor_AGM.updateRow(row_AGM) #delete any locks del row_AGM del cursor_AGM