How to detect a manual user cancel in arcpy?

2740
2
11-23-2011 03:59 PM
AndresSevtsuk
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)
0 Kudos
2 Replies
RichKrabill
Esri 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
0 Kudos
DanielDillard
New Contributor II
Is there a general way to detect when the user clicks the Cancel button?