HOW TO
Relationship classes can be created on a geodatabase with the Standard or Advanced ArcGIS Desktop license. Relationship classes manage the associations between objects in a feature class and a table. As there can be multiple geodatabases within a workspace, manually checking if a relationship class exists in a geodatabase can be tedious. This article provides an alternative method to determine if there is a relationship class in all the geodatabases within a workspace using ArcPy.
import arcpy from arcpy import env
workspace = env.workspace = r"<workspace_location>"
def detectRelationship(): rc_list = [c.name for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"] rc_list # List the names, origin, and destination of the relationship class for rc in rc_list: rc_path = workspace + "\\" + rc des_rc = arcpy.Describe(rc_path) origin = des_rc.originClassNames destination = des_rc.destinationClassNames print ("Relationship Class: %s \n Origin: %s \n Desintation: %s" %(rc, origin, destination))
detectRelationship()
The following code block and image shows shows the full script and the result:
import arcpy from arcpy import env workspace = env.workspace = r"C:\Users\USER\Desktop\Test_case" def detectRelationship(): rc_list = [c.name for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"] rc_list for rc in rc_list: rc_path = workspace + "\\" + rc des_rc = arcpy.Describe(rc_path) origin = des_rc.originClassNames destination = des_rc.destinationClassNames print ("Relationship Class: %s \n Origin: %s \n Desintation: %s" %(rc, origin, destination)) detectRelationship()
Get help from ArcGIS experts
Download the Esri Support App