Joining a table and calculating a field in ArcGIS Pro SDK

2593
4
04-07-2020 04:15 PM
GyanendraGurung
New Contributor III
1 4 2,593

Joining a table is easy. In ArcGIS Pro, you simply right-click a table, goto "Join and Relate" and then select "Add Join". This takes you to a Geoprocessing tool where you select the input join field and output join field and voila, your table is joined !

1. But, when it comes to using the "management.AddJoin" with ExecuteToolAsync(), you actually end up with a new table with the two tables joined together: 

  1. var argsAddJoin = gp.MakeValueArray("C:\\Project\\Sample_database.gdb\\Input_Table""INPUT_ID", "Table_to_Join""OUTPUT_ID""KEEP_ALL");  
  2. var resultAddJoin = await gp.ExecuteToolAsync("management.AddJoin", argsAddJoin);  
  3. string resultingJoinedTable= resultAddJoin.ReturnValue;  

 

2. Then, if you want to recalculate a field in the input table, you would have used the following python code:

  1. // Calculate Field //  
  2. arcpy.management.CalculateField("Resulting_Joined_Table""Resulting_Joined_Table.FIELDNAME""!Table_to_Join.FIELDNAME!""PYTHON3"''"TEXT")  

and expect to use the following code in C#:

  1. var argsCalculateField = gp.MakeValueArray("Resulting_Joined_Table""Resulting_Joined_Table.FIELDNAME""!Table_to_Join.FIELDNAME!""PYTHON3""""TEXT");  
  2. var resultCalculateField = await gp.ExecuteToolAsync("management.CalculateField", argsCalculateField);

But, this won't work. You actually have to reference the original input table that you had "wished to join" in as the input table's name:

  1. var argsCalculateField = gp.MakeValueArray("Resulting_Joined_Table""Input_Table.FIELDNAME""!Table_to_Join.FIELDNAME!""PYTHON3""""TEXT");  
  2. await gp.ExecuteToolAsync("management.CalculateField", argsCalculateField);

4 Comments
About the Author
GIS/CAD Analyst/Developer