Trying to list datasources in mxds

المشرف العام

Administrator
طاقم الإدارة
I've written a tool that prompts the user for a directory path, and optionally a single mxd. It then crawls the directory for mxds (or just the single one) and writes some of the properties of the layers in each mxd to a csv file. Most of this works fine, except none of the data sources are listed. I've seen the question here, but can't see where mine is going wrong. The other properties are written just fine. Thanks for any help.

import arcpy, os, fnmatch, csvmxddirectory = arcpy.GetParameterAsText(0)mxd_single = arcpy.GetParameterAsText(1)outputcsvlocation = arcpy.GetParameterAsText(2)mxd_list = []if len(mxd_single) > 0: mxd_list.append(mxd_single)else: for dirpath in os.walk(mxddirectory): for filename in dirpath[2]: if fnmatch.fnmatch(filename, '*.mxd'): mxd_list.append(os.path.join(dirpath[0], filename))if len(mxd_list) > 0: outputcsv = open(outputcsvlocation, 'wb') writer = csv.writer(outputcsv, dialect = 'excel') writer.writerow(['Mxd path', 'Layer Name', 'Layer Description', 'Layer Source']) for mxdpath in mxd_list: mxdname = os.path.split(mxdpath)[1] try: mxd = arcpy.mapping.MapDocument(mxdpath) dfList = arcpy.mapping.ListDataFrames(mxd) for df in dfList: for lyr in arcpy.mapping.ListLayers(mxd, '', df): if lyr.supports('dataSource'): layerattributes = [mxdpath, lyr.longName, lyr.description, lyr.dataSource] writer.writerow(layerattributes) except Exception as e: arcpy.AddMessage('EXCEPTION: {0}\n{1}\n{2}\n'.format(mxdpath, lyr.longName, e)) writer.writerow(['', '', '', '']) del mxd outputcsv.close()else: arcpy.AddError('No ArcMap documents found')

أكثر...
 
أعلى