I have a script that lists all layers in an MXD and I have a script that lists all broken layers in an MXD (http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/listbrokendatasources.htm). I want to list all layers, their name, source, description, and whether or not their source is broken. Can anyone help me with this? I can't quite figure out how to integrate the two...
import arcpy, os, fnmatch, csv
#Create an empty list of ArcMap documents to process...
mxd_list=["A.mxd", "B.mxd", "C.mxd"]
for mxd in mxd_list:
mxd = arcpy.mapping.MapDocument(mxd)
mapPath = mxd.filePath
fileName = os.path.basename(mapPath)
layers = arcpy.mapping.ListLayers(mxd)
filepath = "C:/Users/USERNAME/Desktop/"+ fileName[:-4]+".csv"
writer = csv.writer(file(filepath, 'wb'))
sourcelist = []
for layer in layers:
if layer.supports("dataSource"):
layerattributes = [layer.longName, layer.dataSource]
#Write the attributes to the csv file...
writer.writerow(layerattributes)
writer.writerow(sourcelist)
del writer
isBroken
property. You should be careful with it, since it does not reflect if the source has been broken since the last time the MXD was written. Anarcpy.Exists ()
will also be necessary.