Get Relationship Classes from Table (Not Workspace)

790
3
Jump to solution
11-21-2013 11:09 AM
brettangel
Occasional Contributor II
Any ideas on how to do this? Originally, I thought I could use the relationshipClassNames from the GDB Table properties, but I only get empty value back (i.e. []). Anybody know why this does not work or what I'm doing incorrectly? Not much to this and the example is pulled straight from ESRI help documents.

desc = arcpy.Describe("myTable") print desc.relationshipClassNames


I found this thread with this code

import arcpy from arcpy import env workspace = env.workspace = r'your_workspace' def detectRelationship():      rc_list = [c.name for c in arcpy.Describe(workspace).children if c.datatype == "RelationshipClass"]      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()


, but I don't need to search the entire DB for all relationships. Only a specific table. I could use this code to ID the table and relationships I want, but would prefer to use the relationshipClassNames from GDB Table to reduce the amount of code.

Any help would be much appreciated.  Forgot to add I'm using 10.1.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor
Hi Brett,

If you run the code in the Python window it will work. If you use a standalone script, it won't :(. To solve this you should make a Featurelayer of TableView and describe those objects instead:

Feature class
import arcpy fc = r'\\nlbltfs01\Projecten\307103\werkdir\fgb\BLS_Copy_Paste.gdb\Leiding' arcpy.MakeFeatureLayer_management(fc,"myLayer") desc = arcpy.Describe("myLayer") print "myLayer: {0}".format(desc.relationshipClassNames)


Results in:
myLayer: [u'ZZRC_Leiding_Afsluiter', u'ZZRC_Leiding_Cap', u'ZZRC_Leiding_Diameterovergang', u'ZZRC_Leiding_Flens', u'ZZRC_Leiding_Isolatiekoppeling', u'ZZRC_Leiding_Las', u'ZZRC_Leiding_Leidingzakbaken', u'ZZRC_Leiding_Wanddikteovergang', u'ZZRC_Leiding_TStuk', u'ZZRC_Leiding_Pigmarker', u'ZZRC_Leiding_Ontluchting', u'ZZRC_Leiding_Mangat', u'ZZRC_Persoon_Leiding']


Table
tbl = r'\\nlbltfs01\Projecten\307103\werkdir\fgb\BLS_Copy_Paste.gdb\Persoon' arcpy.MakeTableView_management(tbl,"myTable") desc = arcpy.Describe("myTable") print "myTable: {0}".format(desc.relationshipClassNames)


Results in:
myTable: [u'ZZRC_Persoon_Leiding', u'ZZRC_Eigenaar_Duiker', u'ZZRC_Eigenaar_KruisendeWeg', u'ZZRC_Inspectieweg_Eigenaar', u'ZZRC_Inspectieweg_Onderhoud', u'ZZRC_KruisendeKabel_Persoon', u'ZZRC_KruisendeLeiding_Persoon', u'ZZRC_Onderhoud_Duiker', u'ZZRC_Onderhoud_KruisendeWeg', u'ZZRC_Persoon_Damwandkoker', u'ZZRC_Persoon_Gebouwen', u'ZZRC_Persoon_Gelijkrichter', u'ZZRC_Persoon_Handhole', u'ZZRC_Persoon_KruisendeMantelbuis', u'ZZRC_Persoon_Pachtkavel', u'ZZRC_Persoon_Peilbuis', u'ZZRC_Persoon_Wbe', u'ZZRC_Persoon_Grondzakbaken', u'ZZRC_Persoon_Leidingzakbaken', u'ZZRC_ZakelijkRecht_Persoon']


Kind regards,

Xander

View solution in original post

0 Kudos
3 Replies
XanderBakker
Esri Esteemed Contributor
Hi Brett,

If you run the code in the Python window it will work. If you use a standalone script, it won't :(. To solve this you should make a Featurelayer of TableView and describe those objects instead:

Feature class
import arcpy fc = r'\\nlbltfs01\Projecten\307103\werkdir\fgb\BLS_Copy_Paste.gdb\Leiding' arcpy.MakeFeatureLayer_management(fc,"myLayer") desc = arcpy.Describe("myLayer") print "myLayer: {0}".format(desc.relationshipClassNames)


Results in:
myLayer: [u'ZZRC_Leiding_Afsluiter', u'ZZRC_Leiding_Cap', u'ZZRC_Leiding_Diameterovergang', u'ZZRC_Leiding_Flens', u'ZZRC_Leiding_Isolatiekoppeling', u'ZZRC_Leiding_Las', u'ZZRC_Leiding_Leidingzakbaken', u'ZZRC_Leiding_Wanddikteovergang', u'ZZRC_Leiding_TStuk', u'ZZRC_Leiding_Pigmarker', u'ZZRC_Leiding_Ontluchting', u'ZZRC_Leiding_Mangat', u'ZZRC_Persoon_Leiding']


Table
tbl = r'\\nlbltfs01\Projecten\307103\werkdir\fgb\BLS_Copy_Paste.gdb\Persoon' arcpy.MakeTableView_management(tbl,"myTable") desc = arcpy.Describe("myTable") print "myTable: {0}".format(desc.relationshipClassNames)


Results in:
myTable: [u'ZZRC_Persoon_Leiding', u'ZZRC_Eigenaar_Duiker', u'ZZRC_Eigenaar_KruisendeWeg', u'ZZRC_Inspectieweg_Eigenaar', u'ZZRC_Inspectieweg_Onderhoud', u'ZZRC_KruisendeKabel_Persoon', u'ZZRC_KruisendeLeiding_Persoon', u'ZZRC_Onderhoud_Duiker', u'ZZRC_Onderhoud_KruisendeWeg', u'ZZRC_Persoon_Damwandkoker', u'ZZRC_Persoon_Gebouwen', u'ZZRC_Persoon_Gelijkrichter', u'ZZRC_Persoon_Handhole', u'ZZRC_Persoon_KruisendeMantelbuis', u'ZZRC_Persoon_Pachtkavel', u'ZZRC_Persoon_Peilbuis', u'ZZRC_Persoon_Wbe', u'ZZRC_Persoon_Grondzakbaken', u'ZZRC_Persoon_Leidingzakbaken', u'ZZRC_ZakelijkRecht_Persoon']


Kind regards,

Xander
0 Kudos
brettangel
Occasional Contributor II
Xander,

Making a TableView worked perfectly!  Thanks a ton.
0 Kudos
brettangel
Occasional Contributor II
If you're following this thread any chance you know how to get the primary and foreign keys from a relationship class?
0 Kudos