AnsweredAssumed Answered

Write Broken Source List to Text File

Question asked by jared_pilbeam on Feb 6, 2017
Latest reply on Feb 7, 2017 by jared_pilbeam

Hi,

 

I'm attempting to print lists of broken source data to a text file using the write to text function, but I'm at a loss. The code I have works up until it's meant to write to the text file. 

 

You'll notice that the write function has nothing between the parentheses. This is because I'm not sure what to put there in order to print the list of broken layers and broken picture elements. In other words, I'm uncertain as to what variable to use for the write function. Basically, I'm trying to write the lists shown in the Interactive Window below (PrtScn) to a text file, and save the file in the workspace folder.  

 

import arcpy
import os
from arcpy import env

# set variables
path = r'\\gisfile\GISmaps\AtlasMaps\ATLAS_MAPS_17\New folder'

# iterates through folder and lists broken layers
for fileName in os.listdir(path):
    fullPath = os.path.join(path,fileName)
    if os.path.isfile(fullPath):
        basename,extension = os.path.splitext(fullPath)
        if extension == ".mxd":
            mxd = arcpy.mapping.MapDocument(fullPath)
            print "current MXD being checked is: " + fileName
            for brknList in arcpy.mapping.ListBrokenDataSources(mxd):
                print "\t broken layer: " + brknList.name
                # iterates through folder and checks for broken picture element source
                for elem in arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT", "*logo*"):
                    print "\t broken picture element name: " + elem.name
                   
                    # Write to text file
                    txtFile = open(path + "{}".format("BrkSrceLst.txt"), "w")
                    txtFile.write("MXDs that have broken source data" + "\n")
                    txtFile.write("----------------------------------------------" + "\n")
                    for f in fullPath:
                        f.write()
                        for ename in elem.name:
                            ename.write()
                    txtFile.close()
                    print "\t completed"

 

Thanks in advance for any help!

Outcomes