How to detect a manual user cancel in arcpy?

2663
2
11-23-2011 03:59 PM
Highlighted
New Contributor
Hi,

I'm running a NA-based arcpy tool, and can't figure out how to tell the code when a user manually cancels the operation in the GUI? If that happens, we want the code to do some clean-up work, but we can't figure out how to let the code know that a user has pressed "cancel". Any thoughts?

Thanks,

Andres
Tags (2)
Reply
0 Kudos
2 Replies
Highlighted
New Contributor
Andres,

If you are running NA Solve tool in background from python window in ArcMap you can use the result object success output parameter.

>>>result = arcpy.na.Solve("Service Area")
>>>resultSuccess = result.getOutput(1)

resultSuccess will be false if cancelled OR if an error occured that prevented the solve.  If the goal is to do cleanup if the solve didn't complete this may be useful information for your purposes.

-Rich
Reply
0 Kudos
Highlighted
New Contributor II
Is there a general way to detect when the user clicks the Cancel button?