Here’s a workaround for getting back a script folder where you can put your Python scripts and modules to be auto-loaded when Rhino starts up!
I post this because:
- the old Rhino scripts folder seems to have been abandoned
- no Rhino developer was able to offer an alternative or even an answer to what happened to the old scripts folder
- adding paths with
sys.path.append()
is currently also not working, on macOS at least
My hope is that someone with a similar workflow than me, may find this helpful!
How-to:
Let me preface this by saying that this method is a workaround, and that you should absolutely keep a backup of your scripts, since an upgrade of Rhino may or may not overwrite what we are going to put into place.
I’ve discovered that on macOS, Rhino 8 - in good Linux fashion - creates a dot directory in your home folder called .rhinocode. It’s an invisible directory that you can gain access too by opening a Terminal (Applications/Utilities/Terminal.app) and typing in open .rhinocode
.
Now, Rhino automatically adds the following paths to sys.path
:
- /Users/<user>/.rhinocode/py39-rh8/site-envs/default-8SYS74YE
- /Users/<user>/.rhinocode/py39-rh8/site-rhinoghpython
- /Users/<user>/.rhinocode/py39-rh8/site-rhinopython
- /Users/<user>/.rhinocode/py39-rh8/site-interop
- /Users/<user>/.rhinocode/py39-rh8/lib/python39.zip
- /Users/<user>/.rhinocode/py39-rh8/lib/python3.9
- /Users/<user>/.rhinocode/py39-rh8/lib/python3.9/lib-dynload
- /Users/<user>/.rhinocode/py39-rh8/lib/python3.9/site-packages
I’ve substituted my username for the generic <user>
. Yours is different.
You can verify the paths by opening a script editor in Rhino or Grasshopper and running the following script:
import sys
print(sys.path)
Knowing this, we can possibly add our scripts and modules to any of these directories, and they’ll get loaded with the rest, right?
I’ve tried putting a module of mine into /Users/<user>/.rhinocode/py39-rh8/site-rhinoghpython and after relaunching Rhino, I was able to successfully import
the module in Grasshopper Python.
This directory doesn’t seem to be scanned recursively for subdirectories though, but the following path is:
/Users/<user>/.rhinocode/py39-rh8/site-rhinoghpython
We can reinstate a scripts directory there, but remember that it might get purged when Rhino is upgraded!
So, we can take this a step further by using a symbolic link instead. This will make sort of a shortcut to a directory somewhere else on your Mac. When the symlink gets deleted, the linked directory remains untouched.
First I recreated a scripts directory, where it was previously located in /Users/<user>/Library/Application Support/McNeel/Rhinoceros/8.0 . This is where I will dump my custom modules and scripts, but you can obviously chose another location.
All that remains is symlinking this directory to /Users/<user>/.rhinocode/py39-rh8/site-rhinoghpython .
Again, open a Terminal and use the following command to put it in place:
ln -s "/Users/<user>/Library/Application Support/McNeel/Rhinoceros/8.0/scripts" ".rhinocode/py39-rh8/site-rhinopython/scripts"
If you choose a different location, you need to change the first path here.
Simply relaunch Rhino and you’ll be good to go.
I’ll use Python 3 from now on, but if you want to do the same for legacy IronPython 2.7 scripts, I would recommend to use a separate scripts folder and symlink to rhinocode/py27-rh8/site-rhinopython/scripts instead.
I haven’t tested this yet, but I don’t see why it shouldn’t work.