I've been reading through some of the other answers but I haven't found a solution to my problem yet. I'm working with ArcMap in Python 2.7 in a standalone script.
I'm trying to select some features based on a two shapefiles in a given .mxd, and export the selection to a new featureclass or shapefile.
Currently my code lists the layers in my .mxd, creates the selection, and attempts to use the
CopyFeatures_management() function - but I get the exception
ERROR 000732: Input Features: Dataset contaminated_land does not exist or is not supported Failed to execute (MakeFeatureLayer).
Here is my code so far:
import arcpy, os, glob, arcpy.mapping as map arcpy.env.workspace = "M:\GIS\Oscar\Land_Charges" os.chdir(arcpy.env.workspace) mxd_list = glob.glob('*.mxd') mxd = mxd_list my_mxd = map.MapDocument(mxd) for mxd in mxd_list: # Looping through all the .mxd's in a folder print mxd my_mxd = map.MapDocument(mxd) frame_list = map.ListDataFrames(my_mxd) df = frame_list activeframe = my_mxd.activeDataFrame layers_list = map.ListLayers(my_mxd,'*',df) test_poly = layers_list #test_poly = "M:\GIS\Oscar\Land_Charges\land_charges.gdb\\test_poly" contaminated_land = layers_list select = arcpy.SelectLayerByLocation_management(contaminated_land, 'WITHIN', test_poly, None, 'NEW_SELECTION' ) arcpy.MakeFeatureLayer_management(select, 'contam_select') arcpy.Delete_management('contaminated_land_select.shp') arcpy.CopyFeatures_management(select, 'contaminated_land_select.shp')
What I am confused about is the contaminated_land shapefile works okay in the
SelectLayerByLocation_management() function, but then tells me that it is invalid for