[GIS] Getting arcpy.AddMessage() to display message from script tool called from another script tool

arcgis-10.2arcpypython-script-tool

I am using a Python script tool within an ArcToolbox in ArcGIS 10.2.

The script calls another python script tool while running but does not display the messages from the called script when using the arcpy.AddMessage() method.

Example:

scribtbox (ArcToolbox)
two script tools

  • script1
  • script2

script1:

import arcpy

# output to the screen
arcpy.AddMessage("Doing routine 1...")
routine1()

# call script2
arcpy.script2_scriptbox

script2:

import arcpy

# output to the screen
arcpy.AddMessage("Doing routine 2...")
routine2()

The output model run dialog box in ArcGIS says:

> Doing routine 1...

and then finishes without saying the message from script2.

I'd like it to say:

> Doing routine 1...
> Doing routine 2...

and then finish.

Is this functionality not built in, am I doing something wrong, or is there some other issue at hand.

Best Answer

When you call a script tool it behaves just like any other geoprocessing tool you call from Python. No messages are automatically added to the console (unless there is an unhandled exception).

What you want to do is use arcpy.GetMessages() and arcpy.AddMessage, AddWarning, AddError, etc. after calling the script tool as described in the help.