How to exit a python script tool but keep the geoprocessing window open?

3177
5
Jump to solution
02-16-2019 02:31 PM
Nicole_Ueberschär
Esri Regular Contributor

Hi folks, 

I have some preconditions to run my python script tool, for example that you have to create a local copy for editing first when using a hosted feature service layer. I can use exit() with an if statement (I also tried exit(0) and exit(1)) and it stops my script but it "pretends" to have ran succesfully which it did not (because I stopped it before proceeding). I would like to show the user a last message so he knows what he has to do before running the script again. Like the system error messages you find in that geoprocessing window but more helpful 😉  

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

You can raise an exception (or try arcpy.AddError) and the window will stay up. But you'd be better using script validation to stop the script from running in the first place.

View solution in original post

5 Replies
DanPatterson_Retired
MVP Emeritus

Where is the script being run?  ArcMap? ArcGIS Pro? standalone script? some other place?

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Luke already gave me the correct answer but to answer your question (and maybe to give a hint to other people reading this): I am running the script from a Script tool (from the toolbox) within ArcMap 10.6. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ahh arcmap… in Pro, the geoprocessing dialog doesn't close and you can addmessage or error stuff, then 'view details'

0 Kudos
Luke_Pinner
MVP Regular Contributor

You can raise an exception (or try arcpy.AddError) and the window will stay up. But you'd be better using script validation to stop the script from running in the first place.

Nicole_Ueberschär
Esri Regular Contributor

Thanks Luke! Why I didn't find that option?! That does exactly what I was looking for. 

I have script validation in my script but there are a couple of still valid steps that would throw an error at a later stage whith an error message that my client would not understand 😉 

0 Kudos