0

I have seen a few question related to listing broken data sources of layers within an MXD MXD list broken links See Link .

I am interested in layers that are not within an MXD. That are sitting within a windows file directory

It seems the syntax is the same , maybe I am passing a file string that is not in the correct format my code is as follows

folderPath = r"C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS"

def Get_Layer_files(Folderpath):

    import arcpy,os

    ws = arcpy.env.workspace = folderPath
    arcpy.env.overwriteOutput = True
    Layer_Container =[]



    Layer_List = arcpy.ListFiles("*.lyr")

    for layer in Layer_List:
        Full_Name = folderPath + "\\" + layer
        Layer_Container.append(Full_Name)
    return Layer_Container


import arcpy

my_list = Get_Layer_files(folderPath)


for file in my_list:

    lyrfile = arcpy.mapping.Layer(file)
    lyrlist = arcpy.mapping.ListLayers(lyrfile)
    for lyr in lyrlist:

        brokenlist = arcpy.mapping.ListBrokenDataSources(file)
        for lyr in brokenlist:

            print lyr

At the moment I think I am passing my layers file that are saved here

folderPath = r"C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS"

That are each listed as

C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS\a_layer.lyr

C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS\b_layer.lyr

Is this what should be passed into the

brokenlist = arcpy.mapping.ListBrokenDataSources('C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS\a_layer.lyr')

I am I missing something simple ?

1

There's a property for layer objects .isBroken, this will return true if the data source is not valid.

Try this

folderPath = r"C:\PROJECT\02_USER_FOLDERS\JOHN_SMITH\LAYERS"

def Get_Layer_files(Folderpath):

    import arcpy,os

    ws = arcpy.env.workspace = folderPath
    arcpy.env.overwriteOutput = True
    Layer_Container =[]



    Layer_List = arcpy.ListFiles("*.lyr")

    for layer in Layer_List:
        Full_Name = folderPath + "\\" + layer
        Layer_Container.append(Full_Name)
    return Layer_Container


import arcpy

my_list = Get_Layer_files(folderPath)
brokenList = []
for file in my_list:
    lyrfile = arcpy.mapping.Layer(file)
    if lyrfile.isBroken:
        brokenList.append(file)
print brokenList
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.