Cannot escape from a Rhino Python script

Hello,
I am trying to have a function that allows the user to pick some points. Maybe one point, maybe dozens. I used the example located here as a starting point:

Rhino Guide Canceling a Python script in Rhino

Here is the minimal example that shows the problem:

import scriptcontext as sc
import rhinoscriptsyntax as rs

# Example: https://developer.rhino3d.com/guides/rhinopython/python-canceling-scripts/

def DotAtPickedPoints(Text, Layer):

	print('Press the ESC key when finished')

	for i in range(10):
		print(i)
		if (sc.escape_test(False)):
			print('Time to return')
			return

		Clicked = rs.GetPoint('Select a point to mark...')
		if Clicked != None:
			print( type(Clicked) )

DotAtPickedPoints('x', 'Default'

But I am obviously doing something wrong because pressing the escape key will never exit the function. Limiting the loop number to ten was easier than killing Rhino with the task manager but will not be useful in the final script.

Bonus points: where do I find the documentation page on scriptcontext.escape_test() ?

Thank you for your help!
Minimum Example.py (479 Bytes)

Hi Henry - this does not help with the Esc question but I’d handle this differently:

    while True:
        Clicked = rs.GetPoint('Select a point to mark...')
        if Clicked is None:
            break
        else:
            print("Point")

Esc testing is more for when an operation is taking a long time, I think, and not to get out of a loop.
-Pascal

1 Like

Thank you Pascal.
This works perfectly.