Python script tool: "Failed to execute.."

883
2
06-29-2010 05:16 AM
PhilMorefield
Occasional Contributor III
This is a tool to process multiple NetCDF files, and requires the installation of a "non-standard" module (Scientific Python by Konrad Hinson). Whenever I run the tool, all of the calculations are performed correctly but the last three lines in the progress box look like this:

Completed script CalculateDelta...
Failed to execute (CalculateDelta).
End Time: Tue Jun 29 08:55:48 2010 (Elapsed Time: 22.00 seconds)

Has anyone seen this before? What is frustrating is that I have a smaller tool that uses the same module and works fine, even adding the output to the TOC with "gp.SetParameterAsText".....which mysteriously doesn't work on this tool, for some reason. I feel like I'm missing something obvious, since this is my first set of script tools that defines a Python function. I've been through the code and tool parameters a dozen times at least looking for errors, and I'm using a Try/Except loop but not catching any errors (script attached).

Thanks in advance.
0 Kudos
2 Replies
PhilMorefield
Occasional Contributor III
*****  UPDATE  *****

Problem solved. I was using gp.AddError() to display messages of different colors. Using that method must raise some flag in the geoprocessor, which automatically displays the "Failed to execute.." message. This also, somehow, stops the gp.SetParameterAsText() method from working which I was using to add output to the TOC.

Long story short: when I took out the gp.AddError() lines, everything worked perfectly. Lesson learned.
0 Kudos
DaleHoneycutt
Occasional Contributor III
Yep... just to clarify, gp.AddError() will "throw an exception" -- the script exits and the calling program receives the exception.  In this case, the calling program is ArcMap (or whatever) and it traps the exception, giving you "Failed to execute" method.

For more info on error handling, see this blog post about error handling.
0 Kudos