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.