AnsweredAssumed Answered

Arcpy: List all layers in MXD and then make a note of whether is it broken or not

Question asked by mrosenberg57 on Jun 27, 2018
Latest reply on Feb 21, 2020 by amonizm

I have a script that lists all layers in an MXD and I have a script that lists all broken layers in an MXD. I want to list all layers, their name, source, description, and whether or not their source is broken. Can anyone help me with this?


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...
   del writer