Hi All,
For a while now I have been looking into some specific script and Rhino commands intetactions, and finally after @Helvetosaur’s question I am writing down a question and few observations that hopefully are interesting for scripters and also that we can get some insight from Rhino team:
So:
it looks like it is currently possible to run scripts while in-command in Rhino. It can just be macro-ed via usual:
_-Runscript ( [script goes here] )
It actually opens up a lot more possibilities for interactive scripts or enhancing macros. I will show some examples below.
But the main question / problem I ran into is: while “-_Runscripted” scripts work well inside commands from macros/buttons, the very same scripts compiled into Rhino commands with script compiler, do not work. So right now I don’t know a way to have a compiled RhinoScript to be able to run transparently while in command, and I think it would be great to have this option. Is it possible to add a switch to the compiler if the command can be executed inside others ? I guess this is a question for @dale, @DavidRutten and @stevebaer.
To make a simple test, I use:
_Move
_Pause
_-Runscript
(
Rhino.Print "In-command test - the script is working OK now."
)
The same one-liner script ( Rhino.Print “In-command test - the script is working OK now.” ) compiled as a Rhino command used in the same macro replacing the “runscript” portion will not work:
Move
Pause
InCommand_test
It will just echo the command name but nothing happens. The compiled script attached: InCommandTest.rhp (6.5 KB) The command is: “incommand_test”. Should autocomplete and run fine on its own, but not inside Rhino commands. Please note, there is nothing inside the script that would break the Rhino command that is active. So I am hoping this can be achievable to make compiled scripts run inside Rhino commands.
–
Here are a few more things to note on using scripts inside commands:
-
It is possible to run a script in command that is ran inside another script. The same example will look like this (need to use chr(34) for quotes and chr(13) for line breaks):
Call Rhino.Command("_Move _Pause _-Runscript (" & chr(13) & "Rhino.Print " & chr(34) & “In-command test - the script is working OK now” & chr(34) & chr(13) & “)”)
-
if doing the above, the local variables from the ‘host’ script will not be visible in the ‘nested’ script, but they will work if using global variables:
Dim strGlobal : strGlobal = "Global variable"
Call Main()
Sub Main()
Call Rhino.Command("_Move _Pause _-Runscript (" & chr(13) & "Call Rhino.Print (strGlobal & " & chr(34) & " + In-command test - the script is working OK now" & chr(34) & ")" & chr(13) & ")")
End Sub
- As I mentioned above, this functionality can help a lot with enhancing interactivity of scripts by using regular Rhino commands in more controlled way. Many things can happen while in command like color changes, selection/deselection, display mode changes, prompts… a lot to try here. Below is an example of a macro (made just for demonstration sake, not really useful) that uses the in-command script to deselect the transformed geometry while in command and adds/changes/deletes text dots in each command step.
Also please note that “~” before macro-ed commands will suppress the command-line options of Rhino commands, so in this case we don’t see the usual Copy=Yes/No in Rotate3D command. This is useful for interactive scripts if you don’t want to expose all the options but just use specific command functionality. The macro below.
Hope this is interesting and we can get a way to make it work with compiled scripts too.
–jarek
-_Runscript (
Dim global_idDot
global_idDot=Rhino.AddTextDot("Select Objects to rotate",array(0,0,0))
)
_Rotate3D
_~Pause
-_Runscript (
Call Rhino.UnselectAllObjects()
)
-_Runscript (
Call Rhino.TextDotText(global_idDot,"Start of rotation axis?")
Call Rhino.ObjectColor(global_idDot,vbRed)
)
~_Pause
-_Runscript (
Call Rhino.TextDotText(global_idDot,"End of rotation axis?")
Call Rhino.ObjectColor(global_idDot,vbBlue)
)
~_Pause
-_Runscript (
Call Rhino.TextDotText(global_idDot,"Angle or first reference point?")
Call Rhino.ObjectColor(global_idDot,vbYellow)
)
~_Pause
-_Runscript (
Call Rhino.TextDotText(global_idDot,"Secondreference point?")
Call Rhino.ObjectColor(global_idDot,vbGreen)
)
~_Pause
-_Runscript (
Call Rhino.DeleteObject(global_idDot)
)