AnsweredAssumed Answered

Calculating field value based on other fields

Question asked by alastair on Feb 16, 2013
Latest reply on Feb 17, 2013 by alastair
Hello All,

I am very new to Python, I am trying to calculate a field based on the values of three other fields.

I have been able get the process to work in Model Builder but when I export the model to Python and import the line of code that calculates the last field to the rest of the script it runs but does not populate the field. (000405 error)

My code looks like this:
## Add field - Wall_mm  arcpy.AddField_management("Svy_Pt","Wall_mm","FLOAT")  # Select Class (SDR) and Diameter then Calculate wall thickness  arcpy.SelectLayerByAttribute_management("Svy_Pt", "NEW_SELECTION", "\"Class\" = 'SDR 9' OR \"Class\" = 'SDR9' AND \"Diameter\" =  450") arcpy.CalculateField_management("Svy_Pt", "Wall_mm", "52.8", "VB", "")  # Add field - Invert_RL  arcpy.AddField_management("Svy_Pt","Invert_RL","FLOAT")  #Calculate Invert_RL  arcpy.CalculateField_management("Svy_Pt", "Invert_RL", "( [RL]-( [Diameter]/1000))+( [Wall_mm]/1000)", "VB", "")

There are 30 different combinations for the Class and Diameter that the code scrolls through before it gets to the second add field command. It works fine in the python window in ArcGIS 10.1 up to the last line where it runs but doesn't populate the table.

I've looked at the online help where it says to use "!" for field names in Python and tried that as well as triple quotes but I think the additional brackets are confusing the arguments for the tool.

Any assistance would be appreciated.