Answers:
该relationshipClassNames
属性应该可以执行此操作,但它似乎对我不起作用(在文件地理数据库中进行了测试,在两个要素类之间创建了关系类,检查了该属性,两个返回的列表均为空)。也许它将为您工作。
按照@ blah238的建议,此python代码列出了地理数据库中的所有关系类,并将它们放在唯一列表中(relClasses):
inGDB = r"D:\mygeodatabase.gdb"
env.workspace = inGDB
#################Getting all Tables and Feature Classes###########
fcs = []
#root of workspace
for item in arcpy.ListFeatureClasses("*"): fcs.append(item)
for item in arcpy.ListTables("*"): fcs.append(item)
fds = arcpy.ListDatasets("*","Feature")
for fd in fds:
env.workspace = inGDB +'\\'+fd
for fc in arcpy.ListFeatureClasses("*"):
fcs.append(fd+'/'+fc)
for tb in arcpy.ListTables("*"):
fcs.append(fd+'/'+tb)
env.workspace = inGDB
relClasses = set()
for i,fc in enumerate(fcs):
desc = arcpy.Describe(fc)
for j,rel in enumerate(desc.relationshipClassNames):
relDesc = arcpy.Describe(rel)
if relDesc.isAttachmentRelationship:
continue
relClasses.add(rel)
print relClasses
我为此苦苦挣扎,直到意识到arcpy可以通过与之关联的表看到关系类。这是一段代码,用于检查长度大于30的关系类名称:
arcpy.env.workspace = 'C:/workspace'
# Local variables
tables = arcpy.ListTables()
# Iterate through tables in file geodatabase (workspace)
for t in tables:
# Get relationship class(es) associated with table
desc = arcpy.Describe(t)
rcs = desc.relationshipClassNames
# Iterate through any relationship classes associated with current table in loop
for r in rcs:
if len(r) > 30:
print 'Relationship class ' + r + ' has ' + str(len(r)) + ' characters.'
我现在是10.5.1,看起来RelationshipClassNames给了我应该像的关系类名称列表
layer = "C:\\Geodatabases\\somegeodatabase.gdb\\my_layer"
desc = arcpy.Describe(layer)
print desc.relationshipClassNames