Batch Renaming Relationship Classes using ArcPy

Batch Renaming Relationship Classes using ArcPy

I'm trying to rename about 100 relationship classes in a Geodatabase. All the relationship classes are named under a naming convention and a standard part of that has changed, i.e:



Renamed to:



I would like to create a small script to automate this if possible, rather than doing it manually.

This code snippet should work for File GDB relationship classes. Uses the Describe object properties (arcpy) and the Rename (Data Management) tool. If your data is in SDE then you will need to account for the fully qualified names, ex. database.schema.abc_feature1_rel

import arcpy import os desc = arcpy.Describe(r'C:UsersDocumentsArcGISDefault.gdb') for child in desc.children: if child.datatype == "RelationshipClass": new_name = "ddd" +[3:] arcpy.Rename_management(child.catalogpath, os.path.join(child.path, new_name))

I was initially having trouble listing the Relationship Classes in the GDB (there is not a "List RelationshipClasses" arcpy function) but found this forum post to be helpful.

This approach uses a list comprehension to rapidly generate the list of relationship classes. The input name is then split by "_" and reconstructed to your specifications.

import arcpy, os workspace = r'C:UsersOWNERDocumentsArcGISDefault.gdb' # Generate the list of relationship classes rc_list = [ for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"] # Loop through the list and rename for rc in rc_list: outname = "ddd" + "_" + rc.split("_")[1] + "_" + rc.split("_")[2] arcpy.Rename_management(os.path.join(workspace,rc), outname)

Watch the video: 10 ΑΠΙΣΤΕΥΤΑ πράγματα που βρέθηκαν στον ΒΥΘΟ της θάλασσας - Τα Καλύτερα Top10