Site Tools


Integrating macros and scripts into your workspace

Macros and scripts can be run in several ways inside Rhino. The best way to integrate them into your workflow will depend on your preferred way of working as well as which platform you are on - the Rhino for Windows and Rhino for Mac environments are somewhat different.

Macros

We'll cover installing Macros first, as they're somewhat simpler to get up and running.

Using 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 out without the need to edit a button every time. The arrow button runs the macro. If there is anything selected in the editor, it runs the just the selected part, otherwise it runs the whole macro. When the macro runs to your satisfaction, copy and paste the macro to a toolbar button or alias. A detailed tutorial on macro development can be found here.

Creating aliases or toolbar buttons to run your macros

The easiest way to save and run a macro is either with an alias or a new toolbar button.

Alias creation is essentially the same on either Mac or Windows:

  • In Rhino, go to Options>Aliases (Windows) or Preferences>Aliases (Mac)
  • In Windows, click the “New” button. On Mac, click the “+” sign in the lower left corner.
  • In the left column, type the alias. Aliases cannot contain spaces or special characters.
  • In the right column next to your new alias name, type or paste in your macro.
  • In Windows. click OK to save the alias. (Mac saves the alias as soon as you're done typing)
  • Done. Now, when you type your alias at the command line, your macro will run.

Toolbar button creation and editing is relatively simple in Windows Rhino.
It is somewhat more complicated in Mac Rhino.

  • For Windows Rhino, there are good explanations in the Help file under the topics
    “Customize toolbars” and “Button Editor”.
  • For Mac Rhino, have a look at this Wiki page on how to customize your tool palettes.

Once you have created your new button, in the editor window, type or paste in your macro, save and close.


Scripts

Scripts are actually small computer programs that can access Rhino core functions and thus allow you to do a much wider array of operations than macros. While creating scripts does require some knowledge of programming and Rhino, running them does not - you can find many already out there on the 'net and the Rhino forum.

For one-time or occasional use, you can simply save a script somewhere on your computer and then call it from inside Rhino using the RunPythonScript command (.py Python scripts, both platforms) or the Runscript command (.rvb Rhinoscripts, Windows only) and then browsing to the script file and Open. However, if you are going to use the script more often, you will be better off setting it up to run with a button or alias, see below.

Organizing your script collection

Storing your scripts in a specific location

Rhinoscripts or Python scripts can be directly pasted into custom toolbar buttons (see below), but this does not work with aliases. A good way to work around this is to place scripts externally in a folder with a link so that Rhino can find them when the command is run. Both toolbar buttons and aliases can link to external scripts. One advantage of this system is that all your scripts can be located in one spot so you can easily find and update them.

Rhino for Windows and Mac both provide default locations for storing scripts. The folders are hidden from the user by design, so here is how to locate them:

On the Windows platform, the default scripts folder path is in the hidden AppData folder. Each version has a different default folder. The full path to it will be:

C:\Users\<yourusername>\AppData\Roaming\McNeel\Rhinoceros\6.0\scripts (or 7.0, etc.)

You can get to it by clicking the Windows “Start” button and typing %appdata%. This will open the \AppData\Roaming folder, you can navigate along the above path from there. To be able to access it quickly again, make a shortcut to the folder on your desktop. You can store both Rhinoscript format scripts (.rvb) as well as Python format scripts (.py).

On the Mac platform, the default scripts folder path is located in the ~Library folder, also hidden. For Mac Rhino 5.0, the full path is

~/Library/Application Support/McNeel/Rhinoceros/Scripts

For Mac Rhino 6.0 and later, the version number has been added to the folder path like in Windows. Each version therefore has its own folder. The full path will be

~/Library/Application Support/McNeel/Rhinoceros/6.0/Scripts (or 7.0, etc.)

You can navigate to the ~Library folder by holding down the Alt key and pulling down the “Go” menu in the Finder, then navigating along the path above. Note: you can only run Python scripts on Mac (.py extension), Rhinoscripts (.rvb) will not run.

Helping Rhino find your stored scripts

On Mac, this is easy - the work has already been done for you - Mac Rhino already knows where the scripts folder is, so scripts located in that folder can be run very simply.

On Windows, it's a little more complicated, there is a bit of work to be done upfront - fortunately you only need to do this once. In order for Rhino to find your scripts, you need to first manually set a file path to the folder. In addition, the paths for Rhinoscript (.rvb) and Python(.py) scripts are set separately in two different places.

For Rhinoscript, go to Options>Files>Search paths, and paste in the full path to the scripts folder and OK.
For Python scripts, first open the script editor using the EditPythonScript command, then go to Tools>Options and enter the path to the scripts folder in Module Search Paths.

Note that no matter where scripts are stored on your computer, they can always be run if you provide the full path to the script in your alias or button. The above procedure simply allows you to call scripts without having to specify the full path. Plus, you will always know where to find them!


Running scripts from aliases or toolbar buttons

For aliases, create them as described above in the first section…
Simply with the filename if you have set a search path - or you are on Mac and the scripts are in the default scripts folder:

Or with the full path if you haven't:

(shown above: Windows)

Do not forget to enclose the file name/path in quotes!
If there are spaces in it and no quotes, the script will not be found!

For toolbar buttons if you have created them:
Open the button editor and use the same text as you would with aliases:

You can also paste an entire script into a button. For that, start with the command
! -_RunScript (for .rvb) or ! _-RunPythonScript (for .py)
followed by a space and an open parentheses. Paste the whole script in after that line. At the end of the script add a close parentheses.


(shown above: Windows)

Don't forget the dash in front of the command, otherwise it will stop and prompt you for what script you want to run. The underbar insures that the _-Runscript/_-RunPythonScript command will run in languages other than English, but it will not insure the actual script will do the same. It has to be written correctly as well. The _NoEcho in front of the command keeps the command line/history from printing the entire script as it runs.

Last edit 29.08.19 - msh

rhino/macroscriptsetup.txt · Last modified: 2021/06/21 by dan