1

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.

asked Jul 31, 2017 at 8:00
3
  • Please read what you have written in your mind. Commented Jul 31, 2017 at 8:21
  • I just tried this in 10.4.1 and it didn't shut down my arcmap.... Commented Jul 31, 2017 at 15:32
  • in 10.2 it does - tested today Commented Jul 31, 2017 at 18:11

2 Answers 2

4

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.

answered Jul 31, 2017 at 8:20
0

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

def RunScript ():
 #code
 #code code
 #code
 #if selection
 if sel:
 return
 #continue code
RunScript ()
answered Jul 31, 2017 at 14:37

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.