I have tried to “install” a somename.rvb script to always be available in Rhino, and I have searched the documentation, but I just don’t find out what approach to take.
I’ve tried adding an Alias (“Shortcut | ! -RunScript _ScriptName”) but no go.
I have no idea actually. The only thing I have ever got to work was loading the script manually into the script editor and run it from there.
Why can’t I find any instruction for how to configure a simple script to always be available inside Rhino?
Hi Rolf - that depends on how the script is written - if the script does not ‘call itself’ then you can add it in Options > RhinoScript and create your alias, and it should work. If the script does call itself, then you should modify it so that it does not before adding to the list of scripts to load at startup.
Option Explicit
Call Main() '<<<<< this calls the Main subroutine - it needs to be removed.'
Sub Main()
blah blah blah
End Sub
It all depens on the fact that the script calls it’s main subroutine or not. Usually to run a rvb script this works if there is a call to the main function in the script:
If you do not want to create a path, and want to make the script run without denoting a path, you can add the path to file search paths. Just add your favourite script path under:
OK, thank you to both @pascal and @clement, you put me on the right track, but it still took me a while to get all the bits in the right order.
To be more precise, including ALL the details that needs to be in order :
Write the script.
And as @pascal says, make sure to leave out the “Call SubName()” (or the “Call Main()” row, which would be in the default code when creating a new script file)
Fig 1. §1 & 2 above:
3, Specify the script file to be loaded on Rhino startup (due to the rule §2 above, the script will not automatically run when loaded) :
Fig 2. Load script :
4, Now add an Alias for calling the script from the command line (“FL”) in this case :
Fig 3. Add Alias :
4, Add this post to the Rhino Help File.
5, Done.
For anyone interested in the script (Find and Set a specified Layer as the CurrentLayer) here it is - FLayer.rvb : FLayer.rvb (1.0 KB)
Hint: Full path can be specified, like so:
PARENT::CHILD::CHILD::ASO
To simplify typing long paths the script also translates any comma (“,”) into the std path delimiter “::”, meaning that also the following path would be found:
PARENT,CHILD,CHILD,ASO
If only the end target layer name is specified (i.e. “ASO” above) the first occurrence in the layer tree is set to CurrentLayer. If the layer name or path is not found, a message indicates so in the command line.
Hi Rolf - my habit is to add a couple of lines at the top of the script to make the alias and register the script to always load:
Rhino.AddStartupScript Rhino.LastLoadedScriptFile()
Rhino.AddAlias "LayerColorAll", "_NoEcho _-Runscript (LayerColorAll)"
Sub LayerColorAll()
blah blah blah
End Sub
You can add multiple aliases for running separate subs in the same script.
I forgot to add the crucial bit: the nice thing about it is you can then drag and drop the rvb onto Rhino and then just type the alias and it all just works…
it would be nice if the filesearchpath can be used to define folders for python scripts in the WIP too. The current method to add those paths inside the Rhino python editor is not easy to discover for new users.
FWIW I like to share the python equivalent of adding an alias.
I made it so, that the alias is the python scriptname minus .py
import os
import rhinoscriptsyntax as rs
def runme():
print 'hello world'
if( __name__ == '__main__' ):
#get the python scriptfile name and compose the macro
macro = '! _-RunPythonScript "{}"'.format(os.path.realpath(__file__))
#strip the extension from the scriptfile to use as Alias
script_name = os.path.basename(os.path.realpath(__file__)).split('.')[0]
rs.AddAlias(script_name,macro)
#call function defined above
runme()
I suppose not, it could even be series of functions in sequence. Anything trailing the if statement is executed.
So … the Alias is added each time you call it as well. It can be polished by checking for the alias before adding it ofcourse.
For me this is my go to way of adding the alias for a script in a one run way.
You could -I guess- add multiple functions to a single script by creating and calling function inside the script that has commandline options. Aliases could then be set to pass the commandline option arguments directly stepping into that option.
@pascal, when I drag the .rvb file over Rhino I cannot drop it on top of Rhino (“parking forbidden” icon is shown). Is there any special area where the script file can be dropped?
Hmm… start a fresh Rhino. As far as I remember, which may not be very far… there is nothing special you’d need to do… Is it just one file or any rvb that shows this?
Hi Rolf - can you drag other files? Images, Rhino files? Are you running it as administrator by any chance? Windows balks at letting drag and drop happen between levels of authority, I believe.
Nope, I tried them all. Both with and without Administrator’s rights. Nada. Resistant.
I tried on my slow laptop beside me, and there it received the scriptfile just fine. Both machines using Win10.
Hm. Now what?
Edit: I also tried on Rhino5 32bit on the same machine that fails for x64, and 32Bit works, but not x64. I also tried starting x64 in Safe mode, but no go.