## 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", "")
Solved! Go to Solution.
# setting 2 variables as in your selection query, # "Class" (string) and "Diameter" (float): >>> Class = 'SDR9' # the Diameter value is purposely set up wrong # (not equal to the value in your query, 450): >>> Diameter = float(500) # just to check that the values were set properly, printing them... >>> print Class, Diameter SDR9 500.0 # setting up an 'if' statement phrased similarly to your sel query, # with 'or' and 'and', no puctuation to separate clauses: >>> if Class == 'SDR 9' or Class == 'SDR9' and Diameter == 450: # case 1: Class == 'SDR 9' evals FALSE # case 2: Class == 'SDR9' evals TRUE # case 3: Diameter == 450 evals FALSE # The following statement will print 'yes' # if the above compound statement evals TRUE. # The final eval of the compound statement can be TRUE only # if case 1 is TRUE or both case 2 and case 3 are TRUE. # 'SDR9' is not equal to 'SDR 9' so case 1 is FALSE # 500.0 is not equal to 450 so case 3 is FALSE. # Then, the compound statement is FALSE; # the print statement will not execute. print 'yes' # indeed, it is confirmed, the print statement did not execute. # trying the alternate string, setting "Class" to 'SDR 9' >>> Class = 'SDR 9' >>> # trying the same 'if' statement: >>> if Class == 'SDR 9' or Class == 'SDR9' and Diameter == 450: # this time Class == 'SDR 9' evals true, of course... # no need to go further, the print statement will execute. print 'yes' yes # the print statement executed due to the final eval TRUE, printed 'yes'. # however, was that the intended result???... # the Diameter is still 500 and intended to test it for the val 450, correct??? # the following shows how to correctly test for either 'SDR 9' or 'SDR9' first, # in addition to testing the Diameter: >>> if (Class == 'SDR 9' or Class == 'SDR9') and Diameter == 450: # now, the only way this compound statement can eval TRUE is if both 'clauses' # on either side of 'and' are TRUE. # however, 500 is not equal to 450, so the final eval is FALSE; # the print statement cannot execute. print 'yes' # indeed, the print statement does not execute (as it shouldn't).
# Process: Calculate Field arcpy.CalculateField_management("Svy_Pt", "Invert_RL", "( [RL]-( [Diameter]/1000))+( [Wall_mm]/1000)", "VB", "")
#Calculate Invert_RL arcpy.SelectLayerByAttribute_management("Svy_Pt") arcpy.CalculateField_management("Svy_Pt", "Invert_RL", "( [RL]-( [Diameter]/1000))+( [Wall_mm]/1000)", "VB", "") arcpy.SelectLayerByAttribute_management("Svy_Pt","CLEAR_SELECTION")
# setting 2 variables as in your selection query, # "Class" (string) and "Diameter" (float): >>> Class = 'SDR9' # the Diameter value is purposely set up wrong # (not equal to the value in your query, 450): >>> Diameter = float(500) # just to check that the values were set properly, printing them... >>> print Class, Diameter SDR9 500.0 # setting up an 'if' statement phrased similarly to your sel query, # with 'or' and 'and', no puctuation to separate clauses: >>> if Class == 'SDR 9' or Class == 'SDR9' and Diameter == 450: # case 1: Class == 'SDR 9' evals FALSE # case 2: Class == 'SDR9' evals TRUE # case 3: Diameter == 450 evals FALSE # The following statement will print 'yes' # if the above compound statement evals TRUE. # The final eval of the compound statement can be TRUE only # if case 1 is TRUE or both case 2 and case 3 are TRUE. # 'SDR9' is not equal to 'SDR 9' so case 1 is FALSE # 500.0 is not equal to 450 so case 3 is FALSE. # Then, the compound statement is FALSE; # the print statement will not execute. print 'yes' # indeed, it is confirmed, the print statement did not execute. # trying the alternate string, setting "Class" to 'SDR 9' >>> Class = 'SDR 9' >>> # trying the same 'if' statement: >>> if Class == 'SDR 9' or Class == 'SDR9' and Diameter == 450: # this time Class == 'SDR 9' evals true, of course... # no need to go further, the print statement will execute. print 'yes' yes # the print statement executed due to the final eval TRUE, printed 'yes'. # however, was that the intended result???... # the Diameter is still 500 and intended to test it for the val 450, correct??? # the following shows how to correctly test for either 'SDR 9' or 'SDR9' first, # in addition to testing the Diameter: >>> if (Class == 'SDR 9' or Class == 'SDR9') and Diameter == 450: # now, the only way this compound statement can eval TRUE is if both 'clauses' # on either side of 'and' are TRUE. # however, 500 is not equal to 450, so the final eval is FALSE; # the print statement cannot execute. print 'yes' # indeed, the print statement does not execute (as it shouldn't).