Hello,
Trying to figure out how to use the Get Count Tool as a variable and to use it in a field calculator expression. Tried to use inline variable substitution but it is not working properly and giving me an error related to string/interger. The Row Count is set as a precondition. Attached is a photo for reference. any advice would be well appreciated!
Can you try without the quotations around Row Count
Tried without the quotations and it only works without any other numbers in the box
ok try this (sentences which start with a # are just comments to you, not part of the code).
# insert this where it says 'code block'
def func(field):
result = (float(field) + 1.0)/ 2.0
return result
#put this where it says Med_PS =
func(%Row Count%)
#if that doesnt work try changing the 'code block' to
def func(field):
result = (float(field[0]) + 1.0)/ 2.0
return result
#if that doesnt work try changing the 'code block' to
def func(field):
result = (float(field.getOutput(0)) + 1.0)/ 2.0
return result
I have spoofed up a similar situation as shown below.
If I attempt to validate the expression I get a Syntax Error as shown above.
If I IGNORE that error message and run the model it runs without error!
My suggestion is to calculate your value first using the Calculate Value tool.
Set the Row Count as precondition to the Calculate Value tool
Calculate Value Expression: ((%Row Count% + 1) / 2
Calculate Value output data type: Expression
Then you can connect the output of the Calculate Value to your Calculate Field tool as an input parameter.