AnsweredAssumed Answered

Export Layers from Map Document to Shapefiles

Question asked by boyle.matt on Aug 29, 2014
Latest reply on Aug 29, 2014 by filipkral

I'm trying to export the contents of a map document to shapefiles and then zip the folder that contains the shapefiles.  Below is the script I have written so far.  It only exports 1 layer instead of the 3 layers that are in the map document.  I'm wondering how to iterate through the data sources and export each one?

 

import arcpy
import os
import glob
import shutil
import time


MapDoc = r'\\...path to mapdoc.mxd'
ShpDirectory = r'\\...path to ShapefileOut folder'
ShpZip = r'\\...path to ShapefileZip folder'


mxd = arcpy.mapping.MapDocument(MapDoc)  
lyrs = arcpy.mapping.ListLayers(mxd) 
for lyr in lyrs:  
    try:  
        print(lyr.name,lyr.dataSource)
    except:  
        print('Unable to retrieve layer information')

inFeatures = lyr.dataSource
inFeatureName = lyr.name

arcpy.FeatureClassToShapefile_conversion(inFeatures, ShpDirectory)

shutil.make_archive(ShpZip, "zip", ShpDirectory)

del mxd 

 

 

I'm wondering what needs to be done to export each individual layer's data source?

 

Thanks in advance!

Outcomes