I'm editing a script to try and create a list of all datasources within MXD's. I've got the script to crawl the file tree and find all the info, but I would like it to output the data for each layer/datasource on a single line, so it is easy to sort in excel.
Can someone take a look at the code I have so far and let me know how to accomplish that?
import arcpy, datetime, os
try:
arcpy.gp.overwriteOutput = True
#Read input parameters from GP dialog
folderPath = arcpy.GetParameterAsText(0)
output = arcpy.GetParameterAsText(1)
#Create an output file
outFile = open(output, "w")
#Loop through each MXD file
count = 0
for root, dirs, files in os.walk(folderPath):
for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)
if os.path.isfile(fullpath):
if filename.lower().endswith(".mxd"):
#Reference MXD
mxd = arcpy.mapping.MapDocument(fullpath)
count = 1
#Write MXD data to file
MapDoc = os.path.basename(mxd.filePath)
MapDocPath = mxd.filePath
#Reference each data frame and report data
DFList = arcpy.mapping.ListDataFrames(mxd)
for df in DFList:
#Format output values
if df.description == "": descValue = "None"
else: descValue = df.description
#Reference each layer in a data frame
lyrList = arcpy.mapping.ListLayers(mxd, "", df)
for lyr in lyrList:
lyrName = lyr.name
if lyr.supports("dataSource"):
lyrDatasource = lyr.dataSource
else: lyrDatasource = "N/A"
outFile.write("Map Document, MXD Path, DataFrame List, Description, Layer name, Layer Datasource")
str = ",";
seq = (MapDoc, MapDocPath, DFList, descValue, lyrName, lyrDatasource);
outFile.write(str.join(seq))
del mxd
outFile.close()
#Open resulting text file
os.startfile(output)
#Delete variables that reference data on disk
del folderPath, output, outFile, fullpath
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))
The error I recieve when I try to run this is as follows:
\MultiMXDReport_crawl.py", line 60, in
outFile.write(str.join(seq))
TypeError: sequence item 2: expected string or Unicode, list found
: 'str' object is not callable
Failed to execute (MultiMXDCrawler).
No comments:
Post a Comment