Model Builder Calculate field

8108
5
Jump to solution
10-02-2018 11:22 AM
JacobZumwalt
New Contributor II

I have a model that has a buffer distance as a parameter. In the attribute table I would like to show this user inputted value. How do I calculate field based on a parameter?

0 Kudos
1 Solution
5 Replies
curtvprice
MVP Esteemed Contributor

To calculate field to a parameter, you use the model variable in the Calculate Field expression. At runtime, the model variable get substituted in before the Calculate Field tool runs.

"%buffer size%"
JacobZumwalt
New Contributor II

I would like to have this field be "dynamic" and update itself by what the user inputs as a buffer value, i.e 5ft  10m or 20yds. 

0 Kudos
JacobZumwalt
New Contributor II

Hi Darren,

I am getting stuck with the variable substitution. My parameters are the feature class and a buffer distance of 10 feet. My expression for calculating the field value is "%Distance%", which is derived from the user parameter. What should my expression be? SQL, String, etc.

Thanks again

0 Kudos
curtvprice
MVP Esteemed Contributor

Jacob, you should not use the quotes I led your wrong there. The quotes get passed literally so it looks like you are trying to calculate a string into a numeric field in the Calculate Field tool.

What is inside the %'s gets passed as if you typed it into the tool, so if Distance is 50, you should add a field buf%Distance% which is seen by Add FIeld as buf50.

If you are entering a buffer distance as linear unit ie 50 feet, you need to manipulate this string with Calculate Value, for example use the expression "%Distance%".split()[0] to get 50 out.