1

I have created a Toolbox (alias: mytool) and a model (name: mymodel; and it takes 2 parameters which are 'this' and 'that') with ModelBuilder. I need to execute this model from a Python script.

arcpy.ImportToolbox(r"c:\temp\MyTool.tbx")
arcpy.mymodel_mytool(r"D:\temp\this", r"D:\temp\that")

The script runs well but didn't print anything. My question is how to check if this model has been successfully executed by printing out messages from the command prompt.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 9, 2015 at 12:48

1 Answer 1

7

Geoprocessing tools will return a result object. If you store the result in a variable you can examine it afterwards.

result = arcpy.mymodel_mytool(r"D:\temp\this", r"D:\temp\that")
# The following will print all the messages associated with the result
print result.getMessages()

The ArcGIS resource page on Results objects lists the properties and methods you can use to examine your result. You can find the status of the tool (e.g. Succeeded/Failed), and print any error messages. http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000046000000

answered Nov 9, 2015 at 12:58
3
  • I got "AttributeError: 'Result' object has no attribute 'GetMessages'". Any idea? Commented Nov 9, 2015 at 13:12
  • @alextc - Apologies, the g is lowercase, i.e. arcpy.getMessages(). I've updated my answer with this change. Commented Nov 9, 2015 at 13:18
  • @alextc No problem! Commented Nov 9, 2015 at 13:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.