AnsweredAssumed Answered

Arcpy Script Field Calculator

Question asked by brianmac1313 on Oct 1, 2019
Latest reply on Oct 2, 2019 by bixb0012

I am having issues getting a field calc script in arcpy to run. It's probably my parameters, but I can't seem to find the error. Please see below. I am 'ranking', one shapefile based on multiple columns (with weights applied). My goal is to import it as a script into a toolbox so a user doesn't have to use arcpy.

 

Thanks in advance!

 

Edit: format, spelling

#import system modules
import arcpy
import os



#set paramaters - parameters are weights
inFC = arcpy.GetParameter(0)



#fieldName_FinalScore = arcpy.ListFields(inFC)
Parameter_1_p = arcpy.GetParameter(1)
Parameter_2_p = arcpy.GetParameter(2)



#convert GetParamter to floats, I thought 
Parameter_1 = float(Parameter_1_p)
Parameter_2 = float(Parameter_2_p)


#field name
fieldName_FinalScore = "FinalScore"



#lower box
expression_FinalScore = "Value(!Criteria1!,!Criteria2!)"



#code block upper
codeblock_FinalScore = """def Value( Criteria_1, Criteria_2):
FinalScore = !Criteria_1! * Parameter_1 + !Criteria_2! * Parameter_2"""



#Execute CalculateField
arcpy.CalculateField_management(inFC, fieldName_FinalScore, expression_FinalScore, "PYTHON_9.3", codeblock_FinalScore)

Outcomes