2

I am working with ArcMap and am using ArcPy.

My task is to loop through MXDs and find broken data sources.

My code is:

mxd = arcpy.mapping.MapDocument(fullPath)
brknMXD = arcpy.mapping.ListBrokenDataSources(mxd)
for brknItem in brknMXD:  
    if brknItem.supports("workspacePath"):
        try:
            source = brknItem.workspacePath
            print  str(brknItem) + ": " +  source
        except:
            print "unexpected error"
            continue
    else:
        print "Layer does not support source"

Some MXDs have TableViews and that is where the code breaks.

Traceback (most recent call last): File "P:\Scripts\Find_MXDs_Broken_Sources.py", line 5, in if brknItem.supports("workspacePath"): AttributeError: 'TableView' object has no attribute 'supports'

I checked within an MXD Python interpreter to see what type of objects are return by arcpy.mapping.ListBrokenDataSources(mxd) and it indicated:

>>> for each in brknMXD:
...     print type(each)
...     
<class 'arcpy._mapping.Layer'>
<class 'arcpy._mapping.Layer'>
<class 'arcpy._mapping.Layer'>
<class 'arcpy._mapping.TableView'>

Clearly I can just set a test to distinguish between these two types, but I don't know how exactly to write it.

Any ideas?

0

1 Answer 1

0

As commented by @MichaelStimson:

You could use the describe statement http://resources.arcgis.com/en/help/main/10.2/index.html#//03q30000001w000000 and look at the dataType, it should be Layer or TableView for the two indicated types, though I'm not sure how well it works with broken objects... give it a go and see what you get: if arcpy.Describe(brknItem).dataType == 'Layer': before .supports(.. line.

and as commented by @BenSNadler:

You can use listLayers and listTables and check if each one is broken Or as noted above, check the type before .supports

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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