Thursday 21 December 2017

ArcPy - find layers with joins

Here is a brute force script for finding layers with JOINs. As there doesn't seem to be a "hasJoin" property I just use arcpy.RemoveJoin_management which throws an exception if there is no join. This is script is only usefull for once off checks.


ArcMap 10.3


 # find (all) joins in MXD by removing them!  
 # usage: copy MXD and run script or run script and don't save MXD as all JOINS will be removed  
 # result will be a list of all layers where JOIN has been removed succesfully  
 import arcpy  
 mxd = arcpy.mapping.MapDocument("CURRENT")  
 layers = arcpy.mapping.ListLayers(mxd)  
 allJoins = ''  
 for layer in layers:  
   try:  
     arcpy.RemoveJoin_management (layer.name)  
     print("join removed: "+layer.name)  
     allJoins += '\n'+layer.name  
   # no join throws exception  
   except Exception as err:  
     print(err.args[0])  
 print(allJoins)  

No comments:

Post a Comment