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?

  • 2
    You could use the describe statement resources.arcgis.com/en/help/main/10.2/index.html#//… 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. – Michael Stimson Feb 12 '18 at 23:24
  • 1
    You can use listLayers and listTables and check if each one is broken Or as noted above, check the type before .supports – Ben S Nadler Feb 13 '18 at 6:10
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, privacy policy and cookie policy

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