[GIS] How to export all the layers from Table of Content to shp file

arcgis-desktopexportlayersshapefile

I have got lots of different layers in the Table of Content panel in ArcMap. I want to export them all in shp format in one go. How can I do that? So far I have been doing it one by one by right clicking on the layer–>data–>export as shp. and it is taking longer time. I want to do them all together.

Best Answer

This could easily be converted into a toolbox script or run directly from the python window in Arcmap. It can be improved by validating the layer name before copying, duplicate naming conventions, drilling into group layers, using different data frames, etc.

But this should get you started for a simple TOC:

import os, arcpy

folder = "path\to\folder"

#Get name of vector layers in the TOC
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
layers = [f.name for f in arcpy.mapping.ListLayers(mxd, "*", df) if f.isFeatureLayer]


for layer in layers:
    #Join output folder to layer name and append .shp
    shp_out = os.path.join(folder, "{}.shp".format(layer))
    arcpy.CopyFeatures_management(layer, shp_out)
Related Question