Hello, I am trying to get a script to set a definition query from a selection. The selection is set by using an intersect from a buffer layer. I know the first part works, because if I just run this, it will create a selection in the mxd. I have also tested the second 'for...' with an mxd open and it works. However, I need to run this with the mxd closed, as it is being newly created. All I get is "OBJECTID IN ()" in the county layer's query.
for lyr in arcpy.mapping.ListLayers (mxd,'HALF_MILE_BUFFER'):
county_lyr = arcpy.mapping.ListLayers(mxd, 'County')[0]
arcpy.SelectLayerByLocation_management(county_lyr,"INTERSECT",lyr)
for lyr in arcpy.mapping.ListLayers (mxd,'County'):
fids = arcpy.Describe(lyr).FIDSet
idfield = 'OBJECTID'
wc = idfield + ' IN (' + fids.replace(';',',') + ')'
county_lyr.definitionQuery = wc
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")