Site Tools


This is an old revision of the document!


How to Set Up and Run Macros and Scripts in Rhino


Creating a button or alias for your macro or script

The simplest way to save and run your macro is from a toolbar button or alias. If you don’t know how to make a new toolbar button or alias, look in the Help file. There’s a good explanation. Once you have your new button (or have chosen to edit an existing one), open the editor by shift right-clicking on the button. For an alias, do the same thing, but instead of creating a new button, go into Options > Aliases and use the New button to create a new alias.

Use the macro editor to work out new macros

The MacroEditor command opens a text editing window in which you can type macros and try them without the need to edit a button every time. The run button on the lower edge of the editor runs the macro, of if there is selected text, it runs the selected text. When it all runs to your satisfaction, copy and paste the macro to a toolbar button.

Paste your macro or script into the button or alias

There are two ways to approach associating the macro or script to your button or alias. First and simplest is to just copy/paste the whole thing into the left or right button box (or in the alias box). The advantage of the button method is that it is portable. That is, if you copy or export the button to another installation the macro goes with it. Once the test is pasted in, click OK to exit the button editor, and you’re ready to go!

The paste-in-button (or alias) method is fine for macros of Rhino commands and shorter, smaller scripts, but it gets a bit unwieldy to edit if there is a great deal of text. For larger scripts, some people like to place them externally in a folder with a link so that Rhino can find them. Both toolbar buttons and aliases can link to external scripts. One advantage of this system is that all scripts are in one spot so you can easily find and update them. The problem is that if you copy your button or workspace for use somewhere else, you have to remember to bring the scripts with it.

Linking to external scripts

To set up an external scripts folder: Find a logical place to create your folder. This may be either in the Rhino/system folder or some other common place. Open the Options dialog, and navigate to the Files tab. In the file search paths box, click the new button and then the little … button and browse to the location of the scripts folder. Then click OK. Exit the options dialog. Rhino will now look for scripts in this folder.

To link your button or alias to an external script: The syntax used will depend on the type of script. If it is a simple text file with normal Rhino commands (like a long macro), you need to use the command ReadCommandFile Filename.txt Substitute the name of your text file for Filename.txt. Paste that string into the left or right button box and you’re good to go. To run a RhinoScript .rvb file use the command LoadScript Filename.rvb instead. That’s all you need to do.


You can also paste an entire RhinoScript into a button. For that, it needs to start with the command RunScript (not LoadScript) followed by a space and an open parentheses. At the end of the script you need a close parentheses.

! -_Runscript (
<Paste in
your entire
script here>
)

Button editor showing pasted in complete RhinoScript

rhino/macroscriptsetup.1597445311.txt.gz · Last modified: 2020/08/14 by 127.0.0.1