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?
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.
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?
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}")
)
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.
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.