I am trying to automate a process using python and arcpy. I have a scenario where a user will open an mxd and edit a polygon layer drawing a new polygon. They will then want to use just this new polygon to undertake a select by location against every other layer (except the polygon itself obviously) in the table of contents.
I need help enabling my code to export one spreadsheet/csv of every layer that is within the search distance (the individual rows of data associated with each feature are not required, simply a yes or no). Below is the code I have so far.
#Imports the modules
import arcpy
#Sets the Map Document
mxd = arcpy.mapping.MapDocument("CURRENT")
#Sets the dataframe
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Overwrites the Output
arcpy.env.overwriteOutput = True
#Output location for the new polygon feature class that will be used for the select by location.
Search_Area = "U:\\Test.gdb\\Search_Area"
#Selects the polygon with the MAX ObjectID from the Convey feature class.
arcpy.Select_analysis(Convey_L, Search_Area, "\"OBJECTID\" = (SELECT MAX( \"OBJECTID\" ) FROM Convey)")
#Defines the layers as everything in the table of contents.
layers = arcpy.mapping.ListLayers(mxd)
#Loops through the layers in the MXD and select everything that is within 200m of the Relevant Area (Search Area)
for layer in layers:
if layer.name != Convey_L:
arcpy.SelectLayerByLocation_management(layer, "INTERSECT", Convey_L, "200 meters", "ADD_TO_SELECTION", "NOT_INVERT")
for layer in layers:
desc = arcpy.Describe(layer)
if desc.fidSet:
print layer.name, "has {0} features selected:".format(len(desc.fidSet.split(';')))
for row in arcpy.da.SearchCursor(layer, "*"):
print row
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")