Goal: Read all joins within a MXD file and its relevant information. This should include: origin layer name, origin attribute name, destination table name, destination table attribute.
To solve this, I used the code snippet from the following post: Seeing all existing joins in any MXD layer in one place?
It all works so far. I am able to read the origin layer name and attribute name. However I'm only able to read the table name of the join table (destination table name), not the name of the attribute which is used to build the join (RelationshipClass.DestinationForeignKey
is always empty). The joins are between FeatureClasses and geodatabase tables (enterprise and file-based). I'm probably missing something...
My code looks like this:
# Main Function
def get_lyr_join_fields(self, display_table, layer_name):
return_list = []
while self.__try_cast(display_table, db.IRelQueryTable):
source_table_name = layer_name
rel_query_table = self.__try_cast(display_table, db.IRelQueryTable)
rel_class = rel_query_table.RelationshipClass
# Join Source Tabelle
source_table = rel_query_table.SourceTable
source_dataset = self.__try_cast(source_table, db.IDataset)
source_class = rel_class.DestinationClass
source_att = rel_class.OriginForeignKey
# Join Destination Tabelle
dest_table = rel_query_table.DestinationTable
dest_class = rel_class.OriginClass
dest_table_name = dest_dataset.Name
dest_att = rel_class.DestinationForeignKey # <--- ALWAYS Empty!
# Build retrun-List
return_list.append("{}:{},{}:{}".format(source_table_name, source_att, dest_table_name, dest_att))
# Get other joins
display_table = source_table
return return_list
# Cast-Method (for COM-Objects)
def __try_cast(self, obj, interface):
try:
new_obj = obj.QueryInterface(interface)
return new_obj
except:
return None
While debugging the code I get the following output for the RelationshipClass
(join Attribute of the origin is read but not for the destination):