How to "install" a .rvb script?

scripts

#1

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?

// Rolf


(Pascal Golay) #2

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

-Pascal


#3

Hi @RIL,

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:

_-LoadScript "C:\YourPathToTheScript\ScriptName.rvb"

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:

_Options > Rhino Options > Files > Search Paths > File Search Paths

now you can run your rvb script without a path like so:

_-LoadScript ScriptName.rvb

If you do not want your script to be placed on the HDD, you can usually run a rvb script from a button command. Example:

NoEcho
! -RunScript(
Rhino.Print "Hello World"
)

The NoEcho part above prevents that the whole scriptsource is always printed in the command line when running the button command.

c.


#4

@pascal, @margaret,

the helpfile topic _RunScript command points to http://www.rhino3d.com/scripting/ which is a 404.

c.


#5

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 :

  1. Write the script.
  2. 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. :slight_smile:

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.

See also Layer search

// Rolf


Layer search
(Pascal Golay) #6

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.

-Pascal


#7

Wow, thank for that tips! That will be very useful for me!

Now you will have to make this thread sticky at the top of the forum… :slight_smile:

// Rolf


(Pascal Golay) #8

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…

-Pascal


#9

@pascal,

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.

c.


#10

Hi All,

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

-Willem


#11

Thanks @Willem, that’s very useful. Does it matter what the function name is? I guess this technique allows for only one function name per file?

// Rolf


#12

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.

Does that make sense?

-Willem


#13

No. :slight_smile:

But its probably just me. I would have to play around a bit with code to figure out what you mean, but I trust that you know what you mean. :slight_smile:

// Rolf


#14

@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?

// Rolf


(Pascal Golay) #15

Hi Rolf - make sure no command is running.

-Pascal


#16

No go. Rhino 5.

Edit: … But in WIP it works. :slight_smile:

// Rolf


(Pascal Golay) #17

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?

-Pascal


#18

My Rhino5 is totally rvb resistant. :slight_smile:

// Rolf


(Pascal Golay) #19

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.

-Pascal


#20

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.

// Rolf