mdRow = 1 mlRow = 1 map_key = 1 connectedLayers = 0 missingLayers = 0 groupLayers = 0 rawLyrList = {} pathList = {} mapList = {} def WriteMapRow(maps): csvRow = [] for k, v in maps.iteritems(): s = k + ',' for val in v: s += str(val) + ',' csvRow.append(s) f = open('S:\Projects\Current\HUD\DATA\Incoming\Maps.csv', 'w') f.write('\n'.join(csvRow)) f.close() def WriteLayerRow(layers): csvRow = [] for k,v in layers.iteritems(): s = str(k) + ',' s += str(v) + ',' csvRow.append(s) f = open('S:\Projects\Current\HUD\DATA\Incoming\Layers.csv', 'w') f.write('\n'.join(csvRow)) f.close() #function to split out actual layers from any group layers def buildLayerList(lyrList): rawLyrList = [] for lyr in lyrList: if not lyr.isGroupLayer: rawLyrList.append(lyr) return rawLyrList for root, dirs,files in os.walk(r'S:\Projects\Current\HUD\DATA\Incoming'): for fname in files: path = os.path.join(root, fname) if path[-3:] == 'mxd': print "Map: " + path try: mxd = arcpy.mapping.MapDocument(path) df = arcpy.mapping.ListDataFrames(mxd) rawLyrList = [] for df in arcpy.mapping.ListDataFrames(mxd): lyrList = arcpy.mapping.ListLayers(mxd, '', df) rawLyrList = buildLayerList(lyrList) for lyr in rawLyrList: if lyr.isBroken: missingLayers += 1 if lyr.dataSource not in pathList and lyr.supports('DATASOURCE'): pathList[lyr.dataSource] = (mlRow) print 'Datasource Appended: ', lyr.dataSource mlRow += 1 else: connectedLayers += 1 mapList[path] = (mxd.filePath.split('\\')[-1], map_key, connectedLayers, missingLayers) print 'Connected: ', connectedLayers print 'Missing: ', missingLayers connectedLayers = 0 missingLayers = 0 groupLayers = 0 mdRow += 1 map_key += 1 del mxd print except: print "Unknown Error" mapList[path] = (mxd.filePath.split('\\')[-1], map_key, 'Unknown Error') map_key += 1 mdRow += 1 del mxd WriteMapRow(mapList) WriteLayerRow(pathList) print "Successful"
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.