6

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.

  • 2
    Why not just import script2 in script1 and call a method? – Nathan W Jan 21 '14 at 23:15
  • 1
    @NathanW one reason might be if you have a customized ToolValidator class in the script tool definition, it is automatically ran when called as such. – blah238 Jan 22 '14 at 0:58
5

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.

  • 1
    You might be able to return a message at the end of the second script back to the first one - but I agree with blah238 - I don't think there is away to write them out in process. – dklassen Jan 21 '14 at 23:20
  • I am using arcpy.AddMessage() to add my own custom message so the 'run dialog box' will keep me updated of where the script is at. Adding my own messages in this fashion 'does' add messages automatically to the console. At least it does for the main script (the one that I run from the toolbox manually) but not for the script that is called within the main script. As @dklassen said, arcpy.GetMessages() might be able to return the custom messages from script2 but it would likely print them all after the run, not in process. Perhaps this is just not built in functionality. – Chaz Jan 22 '14 at 16:01
  • 3
    It is not, at least not in arcpy. In ArcObjects I believe there are is an interface with a callback (IGPMessages) to get messages as soon as they are created, but AFAIK this is not exposed in arcpy. – blah238 Jan 22 '14 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.