How can I stop a long Cadwork Python script with ESC during execution? #332
Unanswered
mankatmalte-dev
asked this question in
Q&A
Replies: 1 comment
-
|
Hello @mankatmalte-dev , There's no built-in ESC listener in the cadwork Python API out of the box, but since you're on Windows you could use import ctypes
import time
VK_ESCAPE = 0x1B # ESC code on Win
def esc_pressed():
return ctypes.windll.user32.GetAsyncKeyState(VK_ESCAPE) & 0x8000 != 0
paused = False
for i in range(1, 501):
if esc_pressed():
if not paused:
paused = True
print(f"Paused at {i}. Press ESC again to resume...")
time.sleep(0.3)
while True:
if esc_pressed():
paused = False
print("Resumed.")
time.sleep(0.3)
break
print(f"Count: {i}/500")
print("Done.")The I just tested it with this vanilla example. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I have a long‑ running Cadwork Python script that loops through many elements (clean dims, keep cutters, subtract, delete, etc.). While it works fine, I’d like to stop it at any moment by pressing ESC.
Any recommendations? Thanks in advance !
Here is my current code:
Beta Was this translation helpful? Give feedback.
All reactions