Make CalculatedField with join between feature class and table from gdb

743
3
06-26-2017 03:32 AM
LouisDECOMBE
Occasional Contributor

Hi, 

I tried to make calculatedfield on a field of the feature classe that was joined with a table but does not success.

Can anyone help me to write correctly the expression.

Thank you very much

# Set environment settings
arcpy.env.workspace = r"C:\Users\Folder"
arcpy.env.qualifiedFieldNames = False

# Set local variables
inFeatures = r"C:\Users\Folder\Name.gdb\FC"
layerName = "FC"
joinTable = r"C:\Users\Folder\Name.gdb\Table_iris_france"
tableName= "table_iris"
joinField = "ID"
joinField2 = "CODE_IRIS"
field1="POP_COURANT"

# Create a feature layer from the vegtype featureclass
arcpy.MakeFeatureLayer_management (inFeatures, layerName)

# Make a table view from the table
arcpy.MakeTableView_management(joinTable, tableName)

# Join the feature layer to a table
arcpy.AddJoin_management(layerName, joinField, joinTable, joinField2)


# Process: Calculer un champ
arcpy.CalculateField_management(layerName, "Pop_COURANT", "!"+tableName+".POP_COURANT2!", "PYTHON")

Tags (3)
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

hard to tell given your field names, but the calculations can only be made in the file that you are joining to not in the file that you using to join.  Try it manually first, to make sure that you have the files in the correct order for the join and hence the file that you can calculate values

0 Kudos
LouisDECOMBE
Occasional Contributor

Hi Dan, 

it works when i did it manually. But as i have more than 50 fields, i wanted to automate it.

I got error message in this step especially in the name of the field that is in the table joined (not the origine). I do not know how to write it.

Thank

# Process: Calculer un champ
arcpy.CalculateField_management(layerName, "Pop_COURANT", "!"+tableName+".POP_COURANT2!", "PYTHON")

0 Kudos
DanPatterson_Retired
MVP Emeritus

if it worked properly manually, go to your Results output and check your syntax vs works there.  It is a useful option and one that will save a lot of time trying to debug syntax that appears to be correct vs what actually works.