ArcGIS Pro Python AddJoin

4730
15
01-12-2021 02:16 PM
Darrin_Smith
New Contributor II

In ArcGIS Pro, I am running the AddJoin tool.  I have run this command from ModelBuilder and from the Data Management Geoprocessing tool.  Obviously, after running the tool, it functions as it should by joining one featureclass to another.  After running from Geoprocessing, I saved as a Python script.  When I create a new script in Pro, then reference the file I just created, it does not create the join.  It runs and completes successfully but no effect?

arcpy.management.AddJoin("INFEATURE1", "JOINFIELD1", "INFEATURE2", "JOINFIELD2", "KEEP_ALL")

Is there some backend event like a refresh or response that occurs from a Geoprocessing tool that would not necessarily be reflected in the Python script?

0 Kudos
15 Replies
DavidBlanchard
Esri Contributor

I can't get it to work either. The script works as expected when copy-pasted into the Python window, but when run as a script, it doesn't apply the join.

Below is the script I modified to try and get it to work (but it did not):

 

import arcpy

in_layer_name = 'Alpha'
join_table = 'C:\\Users\\dblanchard\\Desktop\\Python_Join\\Default.gdb\\Beta'
join_field = 'JID'

# Get the currently active map
aprx = arcpy.mp.ArcGISProject('CURRENT')
map = aprx.activeMap

# Get the in layer from the map
in_layer_list = map.listLayers(in_layer_name)

if len(in_layer_list) == 1:
	in_layer = in_layer_list[0]
	arcpy.management.AddJoin(in_layer, join_field, join_table, join_field, "KEEP_ALL")
	aprx.save()

else:
	arcpy.AddError('Found {} layers matching the "{}" name when only 1 was expected.'.format(len(in_layer_list), in_layer_name))

 

I also experienced this issue when using ModelBuilder. It works if I run it with the model open, but if I close the model and run it from the toolbox, it doesn't apply the join.

I would suggest you log a support ticket if you have access to Esri Support. Unfortunately, I cannot log a support ticket on your behalf.

A workaround which may be suitable for you is to use a Task. I have a tried a simple task which has the Add Join tool in it and it works as expected.

0 Kudos
Darrin_Smith
New Contributor II

Thanks for the responses.  I will go to Esri support.  I am also confirming it is successful as a Task. 

One note about your ModelBuilder comment.  I understand a Model will not run again after it has been run without first doing a Validate.  If I run from the ModelBuilder tab, it will display the attached message.  If I simply Run as a geoprocess, it will give me a green check, but does nothing probably because it needs to be validated.  My question on the side is, do you know how to automate validating a model?  I would love to run a Python script that would loop through all my Models and validate them.  Otherwise, I must open them up in Edit mode and Validate--Run.

0 Kudos
DanPatterson
MVP Esteemed Contributor

Validate Join (Data Management)—ArcGIS Pro | Documentation might be a good addition prior to AddJoin and check its results


... sort of retired...
0 Kudos
Scott_T_Anderson
New Contributor III

Did ESRI ever respond to this issue?  I see this problem as well.  Frustrating.

0 Kudos
meloking_PNM
New Contributor III

echoing Scott's question. I'm seeing the same issue. Would love to know if/how you resolved it?

0 Kudos
by Anonymous User
Not applicable

The docs 'quietly' say at the end of the last bullet that the join is temporary: "This join is temporary." so you must save the output for it to persist. Maybe try saving the output to a new featureclass?

If you also look at their examples, they all include a Copy Features method at the end.  

I do think they should emphasize that the join is temporary and you must save it for it to last.

0 Kudos