You would probably like to wrap this code into a Python add-in which you could put into a button in your ArcMap UI.
There is no way to tell using arcpy whether a layer has any joins, however, this will be visible if you explore its fields. After join is established, each field will be prepended with the layer's name in the form layer_name.field_name. If there is a dot (.) in the field name, then the layer has the join.
for lyr in arcpy.mapping.ListLayers(arcpy.mapping.MapDocument('current')):
if len([f.name for f in arcpy.ListFields(lyr)][0].split('.')) > 1:
print lyr
Theoretically, even just accessing the OID should suffice (if you have many layers to go through, it could take extra time listing all the fields). So, just limit the field type;
for lyr in arcpy.mapping.ListLayers(arcpy.mapping.MapDocument('current')):
if len([f.name for f in arcpy.ListFields(lyr, field_type='OID')][0].split('.')) > 1:
print lyr
To get the name of the joined table (the one you would see under the Joins & Relates tab of the Layer Properties dialog window), you would need to iterate over the fields of each layer that has joins and find unique dataset names in the fields names.
for lyr in arcpy.mapping.ListLayers(arcpy.mapping.MapDocument('current')):
if len([f.name for f in arcpy.ListFields(lyr, field_type='OID')][0].split('.')) > 1:
print lyr
print set([f.name.split('.')[0] for f in arcpy.ListFields(lyr)])
if lyr.isFeatureLayershould suffice I guess. – Alex Tereshenkov Feb 13 '18 at 16:19.ColumnNameto a gdb feature class, but then when you add the feature class to a map, the dot is automatically removed as soon as you add the join, I've just tested this. Could you please share with us how the dot could persist? Thanks! – Alex Tereshenkov Feb 14 '18 at 07:36comtypesto get the joined data's data name and optionally data source. – Alex Tereshenkov Feb 14 '18 at 07:38database.owner.fieldnamename for some of the fields of the resulting tables. I think "area" was one of the names, but I ported ninety-something tables, and remember tripping over more than one such pseudo-reserved name. I worked around it by trapping for'.' in field.nameand splitting the string when necessary. – Vince Feb 14 '18 at 11:27