0

I am trying to take a Value from a ModelBuilder Feature Selection Iterator and pass it to the Calculate Field Python Expression in order to write values to the field of a feature selection in ArcGIS Pro 2.9.0.

My Model

My model iterates over the Features in Gridline_Grid by PageName, Value becomes the PageName Value. Then that Selected Feature is used to Select By Location all the NRN_Anno features intersecting it. Then the Selection has it's field GRIDS calculated using a Python expression that is designed to look at GRIDS and if it is 0 recalculate it to %Value% (the value from the iterator) if it is not 0 pass the current GRID value to a concatenate expression with %Value% and recalculate the field to a concatenation of both values.

def reclass(GRIDS):
if (GRIDS == '0'):
    return str(%Value%)
else:
    return (GRIDS)+', '+ str(%Value%)

The model keeps telling me the Value sotred in %Value% is not defined. This is telling me that python is returning the value from the parameter %Value% but I cannot seem to get it to read it as a string.

What am I doing wrong?

2 Answers 2

1

Apparently '%Value%' works... not sure why.

def reclass(GRIDS):
    if (GRIDS == '0'):
        return '%Value%'
    else:
        return (GRIDS)+', '+ '%Value%'
1

Adding on to your answer, the note in the Inline variable substitution states:

"You must enclose inline variables that are strings within quotation marks ('%string variable%') in an expression. Inline variables that are numbers do not require quotation marks."

1
  • Thank you for clarifying, I didn't see that anywhere I honestly just started throwing crap at the wall to see what stuck when I found the answer. It seems to me esri made that less intuitive than what it needed to be...
    – MrKingsley
    Nov 18, 2021 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.