see http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000066000000would 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!)
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">RemoveAllJoins</SPAN><SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""Remove all joins from a layer or table view"""</SPAN> flds <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>f<SPAN class="punctuation token">.</SPAN>name <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFields<SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN> wk <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>dirname<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>catalogPath<SPAN class="punctuation token">)</SPAN> joins <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>ParseFieldName<SPAN class="punctuation token">(</SPAN>f<SPAN class="punctuation token">,</SPAN> wk<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">", "</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> flds<SPAN class="punctuation token">]</SPAN> joins <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>set<SPAN class="punctuation token">(</SPAN>joins<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># unique the list</SPAN> <SPAN class="keyword token">if</SPAN> joins<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">"(null)"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"no join active"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># remove base table name from list and remove all joins</SPAN> joins<SPAN class="punctuation token">.</SPAN>remove<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>baseName<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> j <SPAN class="keyword token">in</SPAN> joins<SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>RemoveJoin_management<SPAN class="punctuation token">(</SPAN>tbl<SPAN class="punctuation token">,</SPAN> j<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Removed join {}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>j<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN> <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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
Sign in to post, follow content, and more. New here? Register for free.