Hi! Need some help fixing a code I found online and am trying to customize to my needs. I have a series of 90 map documents, where each one is a different school district and shows the railroad crossings within its boundaries. What I would like the code to do is iterate through each map document, select by location all crossings that intersect the school district within 150 feet, create a list of the ObjectIDs from those selected points, then throw that list of values into the layer's definition query. The list of crossings should therefore be unique to each map document. Here is what I have so far (not set up for iteration yet):
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, '')[0]
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == "Crossings":
Point = lyr
if lyr.name == "Current School District Boundaries":
Polygon = lyr
arcpy.SelectLayerByLocation_management(Point, "WITHIN_A_DISTANCE", Polygon, "150 Feet", "NEW_SELECTION")
pointList = []
for row in arcpy.SearchCursor(Point):
strrow = str(row.OBJECTID)
pointList.append(strrow)
txt_row = ','.join(pointList)
row_list = '(' + txt_row + ')'
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.name == "Point":
lyr.definitionQuery = ' "OBJECTID IN" + row_list '
arcpy.SelectLayerByAttribute_management(Point, "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management(Polygon, "CLEAR_SELECTION")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.save()
I can see the code working when I run it, and it doesn't kick out any errors, but when I check the definition query, it hasn't updated. What am I doing wrong? Thanks in advance!