I have several layers in an ArcMap Document. All of these layers are stored as shape files.
Specific features of the said layers are selected. I want to export the data as shapefile programatically. How can I do this using arcpy?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI have several layers in an ArcMap Document. All of these layers are stored as shape files.
Specific features of the said layers are selected. I want to export the data as shapefile programatically. How can I do this using arcpy?
Try..
## This script will look for all the layers that have feature selected in them in the TOC and export them in seperated shapefile.
##output layer name will be the original name+ _selected e.g. luzon_loss_selected
import arcpy
arcpy.env.overwriteOutput = True
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames( mxd, "Layers")[0]
layers = arcpy.mapping.ListLayers(mxd, "*", df)
output_folder = r'C:\Users\YOUR_USER_NAME\Desktop\test' ##folder path of output
for layer in layers:
Sel=arcpy.Describe(layer)
if Sel.FIDset:
arcpy.FeatureClassToFeatureClass_conversion(layer,output_folder,layer.name + "_selected","","","")