Monday, 29 February 2016

arcgis desktop - Batch export all layers in ArcMap document that have selected features?


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?


Sample view of my arcmap workspace



Answer



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","","","")

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...