Export ListLayer to CSV or Excel

764
1
12-03-2012 05:08 PM
RaziMosadeghi
New Contributor
Hi

Is there any python script to list all the layers within a mxd (ListLayer function) and export the list to a CSV file?
Tags (2)
0 Kudos
1 Reply
by Anonymous User
Not applicable
You can try something like this:

import arcpy, sys, traceback

mxd = arcpy.mapping.MapDocument(r"G:\WIU\projects\Emerald_ash_borer\dispersal.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]

f = open(r"G:\WIU\projects\Emerald_ash_borer\Layer_list.csv", "w")
f.write("Layers\n")
for lyr in arcpy.mapping.ListLayers(mxd, "*", df):
    f.write("%s\n" %lyr)
f.close()
0 Kudos