V7 bug in running script from button, ESC is not released

Hi guys, I have a script that runs just fine from the editor, but when I put it in a button I can only RUN IT ONCE if I hit ESC.
It appears that the ESC registration is not released, so next time I run it it terminates prematurely.

Try putting this in a button:

! _NoEcho  _-RunPythonScript (

import scriptcontext
import rhinoscriptsyntax as rs

n = 0
limit = 100
while True:
    rs.Prompt("test "+str(n)+" of "+str(limit)+" (Press ESC to terminate)")
    n += 1
    rs.Sleep(100)
    if n> limit:
        break
    
    if scriptcontext.escape_test(False):
        print "ESC pressed"
        break #get out of the loop
print "Done"

)

Ps! That example is just a simple example and not the actual script of course :grinning_face_with_smiling_eyes:

Hi @Holo,

Does this work any better?

if scriptcontext.escape_test(False, True):

– Dale

1 Like

Hi @dale
I’ll try! But what does adding the True do?

Edit: It partly works. The next run after hitting ESC autoterminates, but the one after that one again works fine.

Is there a Rhino.“esctest” too that could work better than scriptcontext?

Edit 2:
I just tried:

import Rhino
if Rhino.RhinoApp.EscapeKeyPressed : print “ESC”

But that prints “ESC” every time I run it, so am I using it wrong, or can I reset ESC in some way?

I am pushing a fix for this with the ScriptEditor command in Rhino 8

!_NoEcho _-ScriptEditor _Run (
#! python 3
import scriptcontext
import rhinoscriptsyntax as rs

n = 0
limit = 100
while True:
    rs.Prompt("test "+str(n)+" of "+str(limit)+" (Press ESC to terminate)")
    n += 1
    rs.Sleep(100)
    if n> limit:
        break
    
    if scriptcontext.escape_test(False):
        print("ESC pressed")
        break #get out of the loop
print("Done")
)