Cancelling Rhino.GetOption

I’m running Rhino 5 on win7. I wrote a vbscript that I connected to a button using the command “!_ToggleScale” which runs fine and cancels stock Rhino functions waiting for command line input before proceeding. I’ve also got a vbscript sub called _SetScale which asks the user for command line input through Rhino.GetOption. It also runs fine, but I found that if it’s waiting for input, the button won’t cancel the script before running _ToggleScale. Debugging shows the _SetScale subroutine doesn’t move past the GetOption line when the button is pressed. Am I missing something in either scripting or the button macro command?

Robert

If I put the following on a button:

_-NoEcho _-RunScript (
lst = Array("One", "Two", "Three", "Four")
arr0 = Array(0, "Single")
arr1 = Array(1, "Boolean", "Off", "On", False)
arr2 = Array(2, "Integer", 4, "New value", 2, 10)
arr3 = Array(3, "Double", 34.76, "New value", 1.0, 100.0)
arr4 = Array(4, "List", lst, 0)
opt = Array(arr0, arr1, arr2, arr3, arr4)
rc = Rhino.GetOption("Scripting options", opt)
If IsArray(rc) Then
For Each i In rc
Call Rhino.Print(i)
Next
End If
)

and then click the button, I am able to cancel the GetOption operation by pressing the key, which is basically what the “!” character does.

Does this work for you?

– Dale

Dale,

That shows the same problem. I put that script in a button and hit the button to bring up the user input request. Then I hit a stock rhino key, such as punching the circle button. The circle command executes to completion, and when it’s done, the user input request is once again sitting there waiting to finish execution.

Robert

Ah yes, I can see this. The ‘issue’ is with the RunScript command - the command that runs RhinoScript code. It is a special type of command called a 'script runner` and, thus, has this behavior - sorry.

Makes sense, then let me ask another newbie question. The issue is more of a big deal for my two scripts because I put them as right/left clicks on the same rhino button and I seem to be really good at accidentally hitting the wrong mouse button. Can I do something in the ToggleScale button macro to send an ESC command before it runs the script to cancel GetOption if it’s running?

Robert

Ok, apart from probably having memory leaks and logic races, this seems to cancel Rhino.GetOption
_-NoEcho _-RunScript (
Dim WshShell
Set WshShell = CreateObject(“WScript.Shell”)
WshShell.SendKeys("{ESCAPE}")
WshShell.SendKeys("_ToggleScale")
WshShell.SendKeys("{ENTER}")
)

How many problems arise with this?

Robert

Ok, so I see via google that there is a Rhino.SendKeystrokes command I can’t find in the help file. This also seems to kill Rhino.GetOption

_-NoEcho _-RunScript (
Rhino.SendKeystrokes chr(27)
Rhino.SendKeystrokes “_ToggleScale”
)

Robert

Odd, I see SendKeystrokes in the helpfile index but not if I search for the keyword SendKeystrokes.

Robert

With further testing, I see that unlike the vbscript SendKeys command, Rhino.SendKeystrokes isn’t cancelling GetOption via the esc character but rather via the default enter added after the esc. I’ll need to dig further.

Robert

This seems to cancel GetOption properly followed by running _ToggleScale

_-NoEcho _-RunScript (
Rhino.SendKeystrokes "!"
Rhino.SendKeystrokes “_ToggleScale”
)

However, the “_-NoEcho” option still gets grabbed by GetOption as an invalid selection.

Robert

A Little more info. _-NoEcho isn’t grabbed by GetOption as an invalid entry. It’s processed internally and GetOption redraws without going to the next line in the script. I also found I still need to cancel any currently running Command before running the new script to get it to play nice with stock buttons like Circle. Here’s my best guess at a workaround.

!
_-NoEcho _-RunScript (
Rhino.SendKeystrokes "!"
Rhino.SendKeystrokes “_ToggleScale”
)

with a similar implementation for the _SetScale button macro to keep it from accidentally running on top of itself. Is there a better solution?

Robert