Tuesday 2 July 2019

arcgis 10.1 - 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:


abc_feature1_rel


abc_feature2_rel


Renamed to:


ddd_feature1_rel


ddd_feature2_rel


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



Answer



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:\Users\\Documents\ArcGIS\Default.gdb')

for child in desc.children:
if child.datatype == "RelationshipClass":
new_name = "ddd" + child.name[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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...