Developer Rhino Page for Python is in VB?

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?

[moved from Rhino for Windows to Rhino Developer]

Hi @tom.norris23,

Looks like the guide was started but never completed. I’ve logged the issue with the author.

https://mcneel.myjetbrains.com/youtrack/issue/WWW-762

Here is a simple, cancelable script:

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()

– Dale

Hi Dale,

Thanks for getting back to me but your script does not allow me to cancel it when it is a command, what am I missing?

import scriptcontext

__commandname__ = "EscpaeTest"

def TimeConsumingTask():    
    for i in range(10000):
        # Was escape key pressed?
        if (scriptcontext.escape_test(False)):
            print "TimeConsumingTask cancelled."
            break
        print i

def RunCommand( is_interactive ):
    TimeConsumingTask()
    return 0

I should add that it works as a script just not as a command

Does it work if you add:

rs.Sleep(1) inside the for loop (outside the if)?

Sleep should allow the Rhino windows pump to execute.
If not, @stevebaer might know more about this.

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?

This plug-in works here:

image

EscapeTestPlugin {5662274f-647e-4845-bc0c-007447ab09f4}.zip (980 Bytes)

Unzip this file into:
%appdata%\McNeel\Rhinoceros\6.0\Plug-ins\PythonPlugins

Thanks,

Giulio


Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

1 Like

And in Rhino 5 does it work for you too?

No it doesn’t. I think @stevebaer or @Alain might know why.

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.

Rhino.RhinoApp.Wait() has no effect for me? :confused:

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.

1 Like