see http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000066000000
would be nice to have the option of removing ALL joins from a table or feature class programatically just like you can from the GUI instead of having to remove them individually.
Instead of passing in the name of the join as a string, use a '*' or '#' to represent all.
Here's a little function that does this. You could use this in an arcpy.mapping script or with the Calculate Value tool in Model Builder. Another approach I've used to drop joins in scripting is to delete the layer or table view and recreate it. (This approach may not work well in Model Builder or a script that operates on an existing layer as it would delete the layer from the map!)
def RemoveAllJoins(tbl):
"""Remove all joins from a layer or table view"""
flds = [f.name for f in arcpy.ListFields(tbl)]
wk = os.path.dirname(arcpy.Describe(tbl).catalogPath)
joins = [arcpy.ParseFieldName(f, wk).split(", ")[-2] for f in flds]
joins = list(set(joins)) # unique the list
if joins[0] == "(null)":
print("no join active")
else:
# remove base table name from list and remove all joins
joins.remove(arcpy.Describe(tbl).baseName)
for j in joins:
arcpy.RemoveJoin_management(tbl, j)
print("Removed join {}".format(j))
return
For anyone referring back to this page, calling arcpy.management.RemoveJoin without the optional join_name parameter will remove all joins from the feature layer or table view.
RemoveJoin will throw ERROR 000229 if no join is present, so be sure to catch arcpy.ExecuteError if you want to handle the exception.
As stated above, running Remove Join with no join name specified will result in removing all joins, in ArcGIS Pro 3.0.
See Ideas in ArcGIS Pro 3.0 for all of the other ideas you can look forward to when you upgrade.
Also be sure to check out the What's New documentation: https://pro.arcgis.com/en/pro-app/latest/get-started/whats-new-in-arcgis-pro.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.