Select to view content in your preferred language

Field Calculator works when run Manually but not in ModelBuilder

1026
5
08-30-2019 10:41 AM
MollyWatson1
Frequent Contributor

I am using ArcGIS Pro 2.4 and have a model that has several steps to automate a process. The model executes as expected with no errors. However, the field calculator tools do not run as expected. The field calculator tool is used to fill in a field called "Layer Name" with a basic string in quotes - like "Tornadoes."  It is also used to calculate another field called "Wildfire Hazard" with a custom Python expression to reclassify integers into text.The expressions is:

def Reclass(Mean):
if (Mean < 2):
return "Low"
elif (Mean >= 2 and Mean < 3):
return "Moderate"
elif (Mean >= 3 and Mean < 4):
return "High"
elif (Mean >= 4):
return "Very High"

When I run the field calculator manually with the basic string and the custom expression, it works. However, when it runs in the model it only writes the first letter of the string in both fields. The geodatabase name where the data is stored does not have any spaces or special characters. Does anybody know why the field calculator won't write the entire expression when used in ModelBuilder?

5 Replies
MichelleTotman
Regular Contributor

Hello Molly,

Are the fields your field calculator script is populating generated as a part of your model? If yes, double-check that the field length is longer than 1.

Michelle

0 Kudos
MollyWatson1
Frequent Contributor

Hi Michelle,

Yes, the fields used in the field calculator are generated using the ModelBuilder model. I did not specify a field length in the "Add Field Tool" originally in the model. I changed the field length to 255 in the model and ran it. The field with the custom expression now writes the entire string, however, the field with the simple expression still only writes the first letter. Thanks for the suggestion.

0 Kudos
MichelleTotman
Regular Contributor

Hello Molly,

Python is very sensitive to indentations. It doesn't look like you have any in your script above. That said, I'm pretty sure you'd be getting errors instead of partial returns.

Michelle

0 Kudos
MollyWatson1
Frequent Contributor

Hi Michelle,

My script has indention. I just didn't copy it correctly in my original GeoNet post. See image below

0 Kudos
MollyWatson1
Frequent Contributor

I recreated the model and specified a field length in the add field tools and now it works properly when using ModelBuilder. Perhaps the original model got corrupt in some way. Thanks for the suggestion to specify the field length.