Rhino for Mac users who are familiar with the Windows version may suffer from scripting envy not being aware that there are ways to write and execute Python scripts in Rhino for Mac. Atom is an open source text editor that’s becoming very popular for good reason. Not only is it very powerful out of the box but it’s also very extensible and that’s why we created rhino-python: an Atom package that assists in writting and executing Python scripts in Rhino.
You might even find the rhino-python package usefull if all you need is a central location from which to launch your scripts. Here’s a one minute preview of a possible workflow.
If you’re interested please read the documentation and give it a try. This is an early release and we’re just getting started so please let us know what you like, what you don’t like, and what you’d like to see in the future.
Hi. There are an infinite number of reasons. From the [starter page]:
You may need Python if you want to:
Automate a repetitive task in Rhino much faster than you could do
manually Perform tasks in Rhino or Grasshopper that you don’t
normally have access to in the standard set of Rhino commands or
Grasshopper components Generate geometry using algorithms Many many
other things. It is a programming language after all.
Since you make guitars (awesome guitars btw!) you could draw fret lines on a fingerboard with the following script for example (over simplified):
import rhinoscriptsyntax as rs
scale_length = 25.5
number_of_frets = 24
f = lambda n: scale_length - (scale_length / math.pow(2, (n/12)))
fret_x = [f(n) for n in range(0,number_of_frets)]
for x in fret_x:
Interesting. I’m not sure if anything i do would benefit from using a script, but it’s good to know the capability is there. I know some basic scripting stuff, but could probably pick it up fairly quickly.
I’m not sure this is any better than the post I just deleted but here it goes …
Your scripts can reside anywhere but if they are not on the search path they can’t be imported by other scripts.
One current limitation is that the python search path is not configurable. That means you can’t import modules that are not under: /Users/NAME/Library/Application\ Support/McNeel/Rhinoceros/Scripts or not in the directory or a subdirectory of the file you’re currently running. Subdirectories need to have a __init__.py file so they are recognised as modules.
you can now import your module from a script that’s in ~/py. Ex:
import mylib.myscript as s
If your library is in a directory that is not under a search path you can create a link to it from /Users/NAME/Library/Application\ Support/McNeel/Rhinoceros/Scripts. If in the previous example the mylib directory is somewhere that’s not on the path you’d do something like this:
cd ~/Library/Application\ Support/McNeel/Rhinoceros/Scripts
ln -s /somepath/mylib mylib # link
The example script:
import mylib.myscript as s
would still work.
Being able to configure the search path is important and we’ll add it sooner than later but in the meantime I hope this workaround is useful.
Cool. I installed the Atom thing, and have noticed the bit of having to CD in terminal before launching atom to get my scripts to show up. Will move them to application support for now as others have mentioned.
I’m noticing the autocomplete is VERY picky and if there’s so much as a missed Uppercase vs lowercase character the code won’t run. (for example the example wouldn’t run when typed, but only after I copied it wholesale from the web page).
The whole reason I dived into it was in wanting to get Thomas Anagnostou’s bad assed gear plug in to run under the mac rhino.
While a coder, I’m not at all fluent in Python, and barely cognizant of VB (which Thomas’s script was done in). I started attempting to translate the VB version over to Python with all the obvious stuff (changing comment format, losing the VB DIMs, nuking the end ifs and changing elseif’s to elif’s etc) but still have quite a ways to go and I’m pretty sure my edits to the lengthy select case stuff in the VB code have more than probably jacked up the indentation in python thus breaking havoc on the logic in the process.
If anybody who’s python savvy wants to have a go at porting the gear script, I’d be thrilled to have a running version.
heh… they must of updated that within the past 4 hours as i went to the latest 2.7.1 this morning.
i haven’t tried it yet but i’m writing python today… i’ll update soon and report back if i find anything is broken.
after a very quick go at 2.8, everything still appears to be properly working with rhino… the one thing i noticed is it’s not honoring my ‘Maximum Visible Suggestions’ preference… mine is set to 10 but it’s showing the long list instead…
OK, now I wanted to try opening Atom from inside Rhino… On Windows, you can actually open another windows app by using the “Run” command inside Rhino… Seems like no such animal in MacRhino, but I saw you can actually launch apps with a python script…