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.
1 Answer 1
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.
-
1You 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– dklassen2014年01月21日 23:20:28 +00:00Commented Jan 21, 2014 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– Chaz2014年01月22日 16:01:00 +00:00Commented Jan 22, 2014 at 16:01
-
4It 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– blah2382014年01月22日 16:14:45 +00:00Commented Jan 22, 2014 at 16:14 -
How would one achieve this functionality if, for instance, script2 was a standalone script and not a script tool?Barbarossa– Barbarossa2023年03月08日 18:19:42 +00:00Commented Mar 8, 2023 at 18:19
Explore related questions
See similar questions with these tags.
ToolValidator
class in the script tool definition, it is automatically ran when called as such.