import arcpy mxd = arcpy.mapping.MapDocument("MXD PATH HERE") layers = arcpy.mapping.ListLayers(mxd) for layer in layers: if layer.supports("dataSource"): # some layers might not support the property "dataSource" print layer.dataSource
Thanks Darren! This worked on my first try for me. WOOO!
import arcpy doc = open("doc.txt", "a") mxd = arcpy.mapping.MapDocument("MXD PATH HERE") layers = arcpy.mapping.ListLayers(mxd) for layer in layers: if layer.supports("dataSource"): # some layers might not support the property "dataSource" print layer.dataSource doc.write(layer.dataSource+"\n")
Using Darren's code above, simply write each layer.dataSource to a text file for printing like so:import arcpy doc = open("doc.txt", "a") mxd = arcpy.mapping.MapDocument("MXD PATH HERE") layers = arcpy.mapping.ListLayers(mxd) for layer in layers: if layer.supports("dataSource"): # some layers might not support the property "dataSource" print layer.dataSource doc.write(layer.dataSource+"\n")
import arcpy, csv mxd = arcpy.mapping.MapDocument("YOUR MXD HERE") layers = arcpy.mapping.ListLayers(mxd) filepath = "NEW CSV FILE PATH HERE" writer = csv.writer(file(filepath, 'w')) for layer in layers: if layer.supports("dataSource"): writer.writerow(layer.dataSource) del writer
import arcpy, csv mxd = arcpy.mapping.MapDocument("YOUR MXD HERE") layers = arcpy.mapping.ListLayers(mxd) filepath = "NEW CSV FILE PATH HERE" writer = csv.writer(file(filepath, 'wb')) sourcelist = [] for layer in layers: if layer.supports("dataSource"): sourcelist.append(layer.dataSource) writer.writerow(sourcelist) del writer