Detecting Join programmatically using ArcPy?
Too bad there's not a hasJoin property on the arcpy.Layer class. I think you can test for a join by looking at field names though. Here's a simple proof of concept for data in a file geodatabase:
import arcpy, arcpy.mapping as arc
def joinCheck(lyr):
fList = arcpy.Describe(lyr).fields
for f in fList:
if f.name.find(lyr.datasetName) > -1:
return True
return False
arcpy.env.workspace = r'<path_to_your_gdb>'
mxd = arc.MapDocument(r'<path_to_your_mxd>')
lyrs = arc.ListLayers(mxd)
for lyr in lyrs:
# ignore group layers
if not lyr.isGroupLayer:
hasJoin = joinCheck(lyr)
if hasJoin:
print '\nFound a join: %s.' % lyr.datasetName
else:
print '\nNo join found on %s.' % lyr.datasetName