Select to view content in your preferred language

Print messages from Calculate Value tool?

02-02-2011 09:41 AM
MVP Esteemed Contributor
This may be an enhancement request, if I am right that there is no way to do this.

I'd like a model tool to return information to the user in a message.

I have tried to print messages from the Calculate Value tool with no luck - the message apparently isn't passed along to the models geoprocessing stream.

def xxx():
  arcpy.AddWarning("This input argument is weak")

The workaround I came up with was to return a value like this

def xxx():

which at least throws a message that perhaps may be seen by the user of the model tool.
0 Kudos
4 Replies
Occasional Contributor II
having the same question here. ESRI engineers please help. It is an important function to debug/track the script. Thanks
0 Kudos
Regular Contributor
arcpy.AddError() is currently a no-op in Calculate Value.

You can, however, raise an error, as in:
 raise arcpy.ExecuteError("This input argument is weak")

However, this generates a whole call stack of errors -- it isn't very pretty, but it works... the model will stop execution and the last message will be "This input argument is weak" ... your user should be able to locate the message easily.

The best solution is to create a little script tool.  Here's the code for a script tool that takes two args, message and severity.  I can post this tool to the script tool gallery later today.  Anyway, if you're up to coding a script tool:

import arcpy

message = arcpy.GetParameterAsText(0)
severity = arcpy.GetParameterAsText(1)
arcpy.SetParameter(2, True)  # Output parameter set to false on error
if severity.upper() == "ERROR":
    arcpy.SetParameter(2, False) # error, don't continue

if severity.upper() == "WARNING":

if severity.upper() == "INFORM":
New Contributor II

Just what I was looking for.  I was also trying to print a message in Calculate Value using 


This works perfectly.  I created a script tool using your code and making the severity a drop down list.

0 Kudos
Occasional Contributor II
Thanks Dale. Seems that's the only way to do it at the moment.

It would be nice if ESRI could consider the customized messaging capability in the future (will add it to ArcGIS idea). Personally I prefer use the Calculate Value tool to run my python code as it keep the code inside the model, so that I won't have to manage three things (python script file, script tool, and model to run the tool). Cheers,

edit: there's a ArcGIS idea post at, if you like the idea please vote it.