Problems calculating field in model builder

3470
7
03-14-2012 06:51 PM
grahamlangley-edwards
New Contributor II
Hello, I am attempting to build a model that adds a new field to an attribute table, lets call it New_Temperature,  and then calculates a value for that field by adding a value, determined by the user, to the original Temperature field.  For example, I would like to create a new field that is 7 degrees more that the original field.  I have included a screen shot of the model that I attempted to build.  Plots is the .shp file with the attribute table.  I got the first step to work, where the model adds a new field, but I get a warning saying that "The process did not execute because the precondition is false." 

I am pretty new to this, so I'm not sure I specified everything correctly.  In the Calculate Temperature box I put "[Tma_ºC_] + %Temperature Change%" for the expression field, so I assume that means the Calculate Field box will take the value that is input in to the Temperature Change box and add it to the original Temperature field, denoted as "[Tma_ºC_]".  Is that correct?


Also, I connected the New Temp Field variable to the Calculate Field box with an Input Table connector, so I guess that the Calculate Field box is using New Temp Field as the input table, which would not work because it is an empty field.  I did, however, try to run the model with the Calculate Field box connected directly to the Plots variable, but got the same error. 

Thanks, any help is greatly appreciated...

Graham
0 Kudos
7 Replies
curtvprice
MVP Esteemed Contributor
"[Tma_ºC_] + %Temperature Change%" for the expression field, so I assume that means the Calculate Field box will take the value that is input in to the Temperature Change box and add it to the original Temperature field, denoted as "[Tma_ºC_]".  


It looks okay in that it looks like a legal VBScript calculate expression (hard to see without the actual tool dialog), but I would avoid putting special characters in your field names. That alone can cause a syntax error parsing a calculate expression. Its best if you can to stick with field names that will work in shapefiles if you can (10 characters, case not significant, start with a letter, "_" being the only special character allowed). I would try it with a less adventurous field name like "Tma_C" and see if that solves your problem.
0 Kudos
grahamlangley-edwards
New Contributor II
Hi Curtis, thanks for your response.  I changed the name of the temperature field to Temp, and was able to get that part to run, although it did not add the Temperature change of 7.1 to the original temperature, but only put 7.1 in every row of the new field.  Also, I keep getting the same error for the Calculate Precipitation box "The process did not execute because the precondition is false."  The expression I have written is "Pa_mm_ * (%Precipitation Change%/100 + Pa_mm_) where Pa_mm_ is the precipitation in millimeters.  I divided it by 100 and added Pa_mm_ again because I want the value to be changed by a percentage.  

Any thoughts?

Again, thanks for your help,

Graham
0 Kudos
grahamlangley-edwards
New Contributor II
Hi Curtis, thanks for your response.  I changed the name of the temperature field to Temp, and was able to get that part to run, although it did not add the Temperature change of 7.1 to the original temperature, but only put 7.1 in every row of the new field.  Also, I keep getting the same error for the Calculate Precipitation box "The process did not execute because the precondition is false."  The expression I have written is "Pa_mm_ * (%Precipitation Change%/100 + Pa_mm_) where Pa_mm_ is the precipitation in millimeters.  I divided it by 100 and added Pa_mm_ again because I want the value to be changed by a percentage.  

Any thoughts?

Again, thanks for your help,

Graham
0 Kudos
grahamlangley-edwards
New Contributor II
By the way here are screen shots of the tool dialogs, hopefully that sheds some light on things. 

Thanks again,

Graham
0 Kudos
grahamlangley-edwards
New Contributor II
Help! Please, help!
0 Kudos
curtvprice
MVP Esteemed Contributor
It looks like you're not using delimeters around field names. Please check the tool help - and maybe use the calculation builder wizard (click on the little calculator icon) for guidance.
0 Kudos
grahamlangley-edwards
New Contributor II
Thanks Curtis for your reply.  I put delimeters around the expressions, but the real problem was simply that I had a negative value as the Precipitation Change parameter.  I simply changed the expression to "[Pa_mm_] * (%Precipitation Change% / - 100) + [Pa_mm_]" putting the negative with the 100, since changes in precipitation will always be negative in this region.

For other people that may have the same issue with the field name problem for the add field and calculate field tool...  Don't get hung up on the name of the bubble in the model builder part, that doesn't have anything to do with model tool parameters.  Just set the naming of fields as a model parameter and run the model from arc toobox and it will run fine.
0 Kudos