Is it possible to programmatically identify the Join Field that is being used to Table Join two datasets together in ArcMap? I am currently using ArcGIS 10.0, SP5 and would prefer an ArcPy solution, however I wouldn't be opposed to other solutions, if an ArcPy solution is not available.
One method I tried was looping through all of the fields and look for a matching "baseName", but that is just an "educated guess" where you are hoping that the fieldnames in both databases are the same.
For a graphic representation of what I am after, I basically want to identify the "Input Join Field" and "Output Join Field" as seen in the "Add Join" dialog, but after-the-fact, of course.
This is a tag-on question to Can a “Join” be detected programmatically?, but in this case I want to extend the functionality to identify the FIELD(s) being used to join the two (or more) datasets together.
Best Answer
Here is an ArcObjects approach, based off this example, to enumerate all joins on a layer and list their destination and source table names and primary and foreign keys:
ILayer
that has one or more joinsILayer
toIDisplayTable
IDisplayTable.DisplayTable
property toIRelQueryTable
IRelQueryTable
:RelQueryTable
'sDestinationTable
andSourceTable
propertiesOriginPrimaryKey
andOriginForeignKey
properties of theIRelQueryTable.RelationshipClass
property.RelQueryTable
'sSourceTable
propertyThis Python script (using comtypes and this helper module) will go through all of the joins, from latest to earliest, and print the destination and source table names, origin primary key and origin foreign key for each join:
Example output, given a source layer with three joins:
For more info, see How do I access ArcObjects from Python?