Hi,
How do i list the Relationship Classes with python ?
For tables, datasets and featuresClass use ListTables, ListDatasets and ListFeatureClasses.
Thanks
workspace = "c:/data/gdb.gdb" rc_list = [c.name for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"]
I have consulted the post above, but found that the solution is out of date and no longer works.
import arcpy, os workspace = r'C:/Users/OWNER/Desktop/test.gdb'# Generate the list of relationship classesrc_list = [c.name for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"]print rc_list
This returned "[]" which is an empty array. This means this is no longer a viable option since I have literally 150 relationship classes to rename and none were returned.
Eventually I want to rename my relationship classes as such:
import arcpy, osfrom arcpy import env # Set workspaceenv.workspace = "C:/Users/XXX/Desktop/test.gdb" #get list of relationship classesrc_list = [c.name for c in arcpy.Describe(env.workspace).children if c.datatype == "RelationshipClass"] #remove all underscoresfor rc in rc_list: out_data = rc.replace("_","") arcpy.Rename_management(os.path.join(env.workspace,rc), out_data)#get the list of relationship classes againrc_list = [c.name for c in arcpy.Describe(env.workspace).children if c.datatype == "RelationshipClass"] for rc in rc_list: # if "reading" in rc OR "action" in rc: #add underscores between name and ATTACHREL if "ATTACH" in rc: out_data = rc.replace("ATTACHREL","TblGPS__ATTACHREL") arcpy.Rename_management(os.path.join(env.workspace,rc), out_data) print (rc) #add underscores between name and rel if "rel" in rc: out_data = rc.replace("rel","TblGPS__rel") arcpy.Rename_management(os.path.join(env.workspace,rc), out_data) print (rc) else: #add underscores between name and ATTACHREL if "ATTACH" in rc: out_data = rc.replace("ATTACHREL","PtGPS__ATTACHREL") arcpy.Rename_management(os.path.join(env.workspace,rc), out_data) print (rc) #add underscores between name and rel if "rel" in rc: out_data = rc.replace("rel","PtGPS__rel") arcpy.Rename_management(os.path.join(env.workspace,rc), out_data) print (rc)
How can I extract the relationship classes from the geodatabase so I can rename them in bulk? I have them in a file geodatabase right now but eventually I will have them in SDE.
Dwynne from Esri posted a bit of code on another post that might help. Cf.:
Gonzalo,
I think you just need to specify your SDE Connection File rather than the .gdb path
workspace = r"DatabaseConnections\Connection to dbInstance.sde" or some such.
Debbie