Write ArcMap Layers to Text File with Python
This script came in real handy for creating the start of a quick reference requested by a client who wanted a list of all layers in a few map documents with a description of the layer, how it was made and where it came from. The client’s custom set of metadata was streamlined with the use of this script.
Change the map and text variable to use it yourself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | import arcpy #map with the layers you want in a text file map = r"D:\Dropbox\2015007-Skyline\02-Working Documents\GIS\02_Maps\02_Map_Production_and_Reports\Task02\T02_High_Schools v4.mxd" #text file where the layers will be printed text = r"C:\Users\brian\Desktop\summary_layers.txt" #set the MapDocument parameter mxd = arcpy.mapping.MapDocument(map) #this line makes the script look at the first data frame in the map doc df = arcpy.mapping.ListDataFrames(mxd)[0] #lists all layers in the data frame layer = arcpy.mapping.ListLayers(mxd, "*", df) #sets and opens the text file target for the layer list outFile = open(text,"w") #loop through the layers in the mxd for lay in layer: #creates a line of text with the layer's name and a line return line = str(lay)+"\n" #writes the layers line name and a line return outFile.write(line) #closes the mxd & text file del mxd outFile.close() |
import arcpy #map with the layers you want in a text file map = r"D:\Dropbox\2015007-Skyline\02-Working Documents\GIS\02_Maps\02_Map_Production_and_Reports\Task02\T02_High_Schools v4.mxd" #text file where the layers will be printed text = r"C:\Users\brian\Desktop\summary_layers.txt" #set the MapDocument parameter mxd = arcpy.mapping.MapDocument(map) #this line makes the script look at the first data frame in the map doc df = arcpy.mapping.ListDataFrames(mxd)[0] #lists all layers in the data frame layer = arcpy.mapping.ListLayers(mxd, "*", df) #sets and opens the text file target for the layer list outFile = open(text,"w") #loop through the layers in the mxd for lay in layer: #creates a line of text with the layer's name and a line return line = str(lay)+"\n" #writes the layers line name and a line return outFile.write(line) #closes the mxd & text file del mxd outFile.close()
Aaaaaand now it’s time to start writing but at least I have a list to start from.