I am trying to find a way to escape python commands and this developer page looks like it should help: Canceling a Python script in Rhino but only the first two code snippets are python then the rest of the page is in VB?
The escape examples work as scripts BUT as commands they do not.
I am finding that in commands rs.sleep() does slow down the but does not give rhino a chance to listen to scriptcontext.escpae_test()
And in commands Rhino.RhinoApp.Wait() has no effect
Has anyone found a way to successful escape python commands in rhino 5?
import scriptcontext
def TimeConsumingTask():
for i in range(10000):
# Was escape key pressed?
if (scriptcontext.escape_test(False)):
print "TimeConsumingTask cancelled."
break
print i
TimeConsumingTask()
Even with the rs.sleep(1) added i am unable to cancel? Its like you say rhino does not have enough time to check or is straight up ignoring the escape check. Even setting the sleep value to some ridiculous value like one second rs.sleep(1000) still does not work.
What are the differences between scripts and commands which might cause this to happen?
Or even if anyone knows any suitable work arounds, are key listerners accessible in python for rhino, or are we just going to run into the same problems, where rhino is in too tight a loop to recognise any inputs?
Thanks
T
Try calling Rhino.RhinoApp.Wait() before your escape test. That allows the Windows message pump to be processed and may help in Rhino 5. I’m not exactly sure why the V5 version doesn’t work when run as a command.
Is there a way to run a python script through the command? I’m away from my computer so I can’t test right now but if the tight loop was in a script which we know works with escape, could we just use the command as a pointer to the script?
Something along the lines of:
Rhino.Command “-RunPythonScript ()
With the path to the script? Just thinking out loud here…
I’m not sure if this is fixable for V5. I would recommend just keeping your script as a script that can be executed with RunPythonScript and create an alias for this if you want it to autocomplete like a command. Sorry I don’t have any better suggestions.