It's definitely not a memory issue, python never peaks beyond 20% or so of my total memory. The code doesn't crash, it simply hangs on a particular map for a lot longer than is necessary before moving on to the next map. Once I identified a couple of those maps, I tried opening them and got the same error message about missing a template. I'm sure that the issue is that the maps are older and are using custom templates that are no longer available. The main point for the code is to inventory a large collection of maps and data that we were given by a client and in order to complete it, I need to try and update as many of the layers as possible in order to get a count of feature classes or shapefiles that are being used across each of the maps.If I can figure out a way to either identify which of the maps are using a template in order to avoid them, or to apply a timer that skips a particular map if it doesn't progress after a certain amount of time, I can at least inventory the maps that aren't corrupted.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"