I have made an ArcMap add-in which has the condition that only one feature can by selected a computed. If there are more features selected or no feature in the selection, a message will pop up that the script should be terminated. I am using the sys module and sys.exit(0) in the condition, but this command terminates ArcMap.

Is there something else that terminates only the running Python script, but not ArcMap entirely?

EDIT: I'm using ArcMap 10.4.

  • Please read what you have written in your mind. – nickves Jul 31 '17 at 8:21
  • I just tried this in 10.4.1 and it didn't shut down my arcmap.... – NULL.Dude Jul 31 '17 at 15:32
  • in 10.2 it does - tested today – nickves Jul 31 '17 at 18:11

That's cool, I didn't know you could shutdown Arc by calling sys.exit().

The in-program python interpreter shuts down with the exit call and since the ArcGIS is depended on it the action shut downs the whole system? Makes sense in this context.

For what you asking, you could wrap your logic in a function and return None at the end of it.


Wrap your code in a function and use return whenever you wish to terminate the script.

def RunScript ():

    #code code

    #if selection
    if sel:

    #continue code

RunScript ()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.