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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 12, 2021 at 17:31

2 Answers 2

1

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

def reclass(GRIDS):
 if (GRIDS == '0'):
 return '%Value%'
 else:
 return (GRIDS)+', '+ '%Value%'
answered Nov 12, 2021 at 17:46
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."

answered Nov 12, 2021 at 21:21
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... Commented Nov 18, 2021 at 14:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.