This is supposed to loop through a directory of MXD's and look for broken links and create a report. I am getting an error, an exception I believe, on one of the data sources. In the MXD it shows a data path (broken) in the properties, and the feature class should support a source, so what could cause this?
It's interesting that all the sources first point to the local machines instance of ArcCatalog followed by the actual SDE path. Does that look right? Could that have something to do with the issue? Many other MXD's and layers are worked fine and were reported befor crashing. If I pull out just this layer and/ or mxd I usualy get the same error in other places too, including stand alone tables. The failed featurclass does not have any joins or relates.
Any guesses at whats going on?
Thanks!
Error message
Last line of report:
print "Importing Modules"import arcpy, datetime, time, osdate = time.strftime("%Y_%m_%d")print "Setting Variables"mxd_Paths = []output = os.path.join (r"S:\Departments\GIS\Data\Admin\Dev\PYTHON\Testing\Reports\Broken_Portal_Links", date + ".txt")print "Building Lists"#Populate mxd_Pathsexclude = ("BAK")for root, dirs, files in os.walk(r"C:\Users\Corey.Fields\Python\Testing\Test_2"): dirs[:] = [d for d in dirs if d not in exclude] for file in files: if file.endswith(".mxd"): mxd_Paths.append(os.path.join(root, file,))#Create r/w output text fileprint "Opening Output"outFile = open(output, 'w')#Report headerprint "Writing Header"outFile.write("Data Source Report: \n")outFile.write(" \n")outFile.write("This report summarizes the names of the individual layers within a map document \n")outFile.write("that does not have a valid data source. \n")outFile.write(" \n")outFile.write("Date: " + str(datetime.datetime.today().strftime("%B %d, %Y")) + "\n")#Reference MXD filesprint "Finding Broken Sources"for mxd in mxd_Paths: mxd = arcpy.mapping.MapDocument(mxd) mxdName = os.path.basename(mxd.filePath).split(".mxd") count = 0 print mxd #Report broken sources print "Report broken sources" #If at least one data source within mxd is broken then: if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0: count = count + 1 #Print the name of the mxd to Text file print "Printing MXD" outFile.write("\n") outFile.write("\n") outFile.write("---------------------------------------------------------------------------------- \n") outFile.write(" MAPDOCUMENT: " + os.path.basename(mxd.filePath) + "\n") outFile.write("---------------------------------------------------------------------------------- \n") outFile.write(" \n") #Array of all layers that have broken data sources, so we can get a count of how many data sources are broken. print "... # of Broken Sources" BDS = arcpy.mapping.ListBrokenDataSources(mxd) #Print the number of broken data sources by counting how many objects make up the BDS array. outFile.write("Number Broken Data Source(s): " + str(len(BDS)) ) outFile.write(" \n") outFile.write(" \n") #Loop through each broken data source print "... Write Broken" for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd): #If the broken data source is actually a data source then print the name and original data source location. if brkLyr.supports("dataSource"): outFile.write("\t Layer name: " + brkLyr.name + "\n") outFile.write("\t Original source: " + brkLyr.dataSource + "\n") else: outFile.write("\t Layer name: " + brkLyr.name + "\n") outFile.write("\t Original source: " + "No Source" + "\n") #Delete locks on the mxd del mxd#Report if no broken sources are foundif count == 0: outFile.write("\n") outFile.write("\n") outFile.write("---------------------------------------------------------------------------------- \n") outFile.write(" NO BROKEN DATA SOURCES FOUND \n") outFile.write("---------------------------------------------------------------------------------- \n")#Print the countprint "Printing count"outFile.write("\n")outFile.write("\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write(" Total number of broken sources: " + count + "\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write("\n")outFile.write("\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write(" END OF REPORT" + "\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write(" \n")#Close the fileoutFile.close()#Open the resulting output text fileos.startfile(output)#Delete all variables that reference data on diskdel mxd_Paths, output, outFile
أكثر...
It's interesting that all the sources first point to the local machines instance of ArcCatalog followed by the actual SDE path. Does that look right? Could that have something to do with the issue? Many other MXD's and layers are worked fine and were reported befor crashing. If I pull out just this layer and/ or mxd I usualy get the same error in other places too, including stand alone tables. The failed featurclass does not have any joins or relates.
Any guesses at whats going on?
Thanks!
Error message
Last line of report:
print "Importing Modules"import arcpy, datetime, time, osdate = time.strftime("%Y_%m_%d")print "Setting Variables"mxd_Paths = []output = os.path.join (r"S:\Departments\GIS\Data\Admin\Dev\PYTHON\Testing\Reports\Broken_Portal_Links", date + ".txt")print "Building Lists"#Populate mxd_Pathsexclude = ("BAK")for root, dirs, files in os.walk(r"C:\Users\Corey.Fields\Python\Testing\Test_2"): dirs[:] = [d for d in dirs if d not in exclude] for file in files: if file.endswith(".mxd"): mxd_Paths.append(os.path.join(root, file,))#Create r/w output text fileprint "Opening Output"outFile = open(output, 'w')#Report headerprint "Writing Header"outFile.write("Data Source Report: \n")outFile.write(" \n")outFile.write("This report summarizes the names of the individual layers within a map document \n")outFile.write("that does not have a valid data source. \n")outFile.write(" \n")outFile.write("Date: " + str(datetime.datetime.today().strftime("%B %d, %Y")) + "\n")#Reference MXD filesprint "Finding Broken Sources"for mxd in mxd_Paths: mxd = arcpy.mapping.MapDocument(mxd) mxdName = os.path.basename(mxd.filePath).split(".mxd") count = 0 print mxd #Report broken sources print "Report broken sources" #If at least one data source within mxd is broken then: if len(arcpy.mapping.ListBrokenDataSources(mxd)) > 0: count = count + 1 #Print the name of the mxd to Text file print "Printing MXD" outFile.write("\n") outFile.write("\n") outFile.write("---------------------------------------------------------------------------------- \n") outFile.write(" MAPDOCUMENT: " + os.path.basename(mxd.filePath) + "\n") outFile.write("---------------------------------------------------------------------------------- \n") outFile.write(" \n") #Array of all layers that have broken data sources, so we can get a count of how many data sources are broken. print "... # of Broken Sources" BDS = arcpy.mapping.ListBrokenDataSources(mxd) #Print the number of broken data sources by counting how many objects make up the BDS array. outFile.write("Number Broken Data Source(s): " + str(len(BDS)) ) outFile.write(" \n") outFile.write(" \n") #Loop through each broken data source print "... Write Broken" for brkLyr in arcpy.mapping.ListBrokenDataSources(mxd): #If the broken data source is actually a data source then print the name and original data source location. if brkLyr.supports("dataSource"): outFile.write("\t Layer name: " + brkLyr.name + "\n") outFile.write("\t Original source: " + brkLyr.dataSource + "\n") else: outFile.write("\t Layer name: " + brkLyr.name + "\n") outFile.write("\t Original source: " + "No Source" + "\n") #Delete locks on the mxd del mxd#Report if no broken sources are foundif count == 0: outFile.write("\n") outFile.write("\n") outFile.write("---------------------------------------------------------------------------------- \n") outFile.write(" NO BROKEN DATA SOURCES FOUND \n") outFile.write("---------------------------------------------------------------------------------- \n")#Print the countprint "Printing count"outFile.write("\n")outFile.write("\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write(" Total number of broken sources: " + count + "\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write("\n")outFile.write("\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write(" END OF REPORT" + "\n")outFile.write("---------------------------------------------------------------------------------- \n")outFile.write(" \n")#Close the fileoutFile.close()#Open the resulting output text fileos.startfile(output)#Delete all variables that reference data on diskdel mxd_Paths, output, outFile
أكثر...