import rhinoscriptsyntax as rs
import scriptcontext as sc
for i in range(20):
And see that it won’t print to the command line nor does it react on ESC press.
so the True/False parameters you are supplying control whether an exception is thrown or not. The second parameter is passed to the host environment.
Secondly, it returns a boolean which indicates whether the escape key was pressed.
Your script causes escape_test to be run three times in each iteration. The second and third times are so close after the first that the chance of getting an escape press between them is negligible so their outcomes will be false, meaning that the associated print statements will not be executed.
Only the first test is likely to register a press. Up to that point the function returns false and that is what we see printed in the command line. When escape is detected the first print statement would print True, but the function is using the default throw_exception=true setting so an exception is thrown and, as there is no exception handling in your script, it stops before getting to the print statement.
(Thus, @Gijs, escape_test() is actually working correctly and RH-72484 is redundant.)
[EDIT: @Gijs the above relates to Iron Python - I missed Holo’s RhinoCode tag - and escape_test does not work in Python 3 in my alternative code anymore than in Holo’s, whereas Dale’s solution below does. Sorry for muddying the waters.]
If you want to halt the script without setting up an exception handling framework you could do this, turning off the exception throw and adding a break statement:
for i in range(20):
print(i, "Escape pressed")
That’s strange. What version of Wip are you on?
I suddenly had issues with adding a point too, and had to restart Rhino for it to work.
Print isnt printing to command either, only to the RhinoCode terminal.
I found another strange thing.
If I use rs.GetObjects(“”,preselect=True) then the command I used took 30 seconds to complete IF objects were preselected. But only 2 seconds if I selected them after the command was started.