The rhino-python package for the Atom text editor and Rhino for Mac

NOTE: This thread is obsolete. Go here to read about setting up Python scripting on Rhino for Mac

We created a new package called rhino-python for the Atom text editor that in combination with Rhino 5 for Mac Build 5A671 provides code completion for RhinoCommon and provides a convenient way to launch your python scripts.

Setup:

  • Download and install Rhino 5 for Mac Build 5A671
  • Download and install the Atom text editor (tested with version 0.174.0)
  • From the “Atom” menu select “Install Shell Commands”
  • Close Atom and open a Terminal window
  • In the terminal window command prompt type:
    apm install autocomplete-plus@1.1.0 apm install rhino-python@0.5.3

Quick Start:

  • From Rhino run the StartAtomEditorListener command.
    • ignore the error: “looking for …PlatformServices.dll could not find file”. That missing file is not necessary and the error message won’t be in the next wip release of Rhino.
  • Launch the Atom editor and save the “untitled” document as mypythonscript.py. The file needs to have a “.py” extension for the rhino-python package to be activated.
  • Type "import " (trailing space) and a window with completion data will pop up. If too much time elapsed between typing the last two characters (t and space) the completion window will not open. If it didn’t you can open it by pressing the shift-ctrl-space keys.
  • As you type “rhinos” you’ll see the completion data being filtered until the only option left is “rhinoscriptsyntax”. Press the “tab” key to accept it. Finish the line so it looks like this: import rhinoscriptsyntax as rs
  • On the next line type “from Rhino.Geometry import Point3d”. The completion data will pop up for “Rhino”, “Geometry”, and “Point3d”. Press the tab key to accept each.
  • For the next line type rs.AddCircle(Point3d.Origin, 5.0) and again notice the completion window after each “.” and keep typing until the desired data is highlighted in the completion window. Press the tab key to accept. After you type the “(” nothing happens that’s because in this release completion data for function arguments is not supported. That will come in a future release.
  • To send the file to Rhino for execution press the ctrl-alt-r keys.

known problems and limitations:

  • completion data for function arguments is not provided in this release.
  • if your script prompts the user for input, the ./samples/CircleFromLength.py for example, the parameter input pane (top left) will not be visible because Rhino doesn’t refresh the display when it comes into focus.
  • this is a first release so I’m sure you’ll find more. Please report them here.

The Atom text editor and the rhino-python package are both early releases. Atom (now at 0.174.0) is evolving rapidly and may introduce breaking changes as it moves towards a 1.0 release so the rhino-python package will need to be updated to keep up with the changes. We chose Atom because it’s a new editor that holds a lot of promise: it is made by the folks at GitHub, is getting a lot of attention, is cross platform, and is open source. Let us know what you think …

5 Likes

Hey Alain,

Cool! No Mac here to test today, will try tonight @home.

Is the idea to also replace the “native” Windows Rhino Python script editor with Atom at some point as well? And will there be at some point a “silent” automatic install when installing Rhino without having to download and configure an external package?

Thanks, --Mitch

nice.

one weird thing i’m seeing right off…

in rhino, draw a line (_Line → click two points)

in Atom, enter

import rhinoscriptsyntax as rs

rs.AddPoint(0,0,0)

(or enter anything that will run actually)

use the atom shortcut keys to run the script and the point is added as expected but i’m also getting a notification:

as in: when the script is run from atom, rhino is completing the script then giving a notification of the last completed command which happened in rhino (and we generally don’t get these notifications unless something takes a long time or you’ve left the application… a long export or boolean operation for example… i’ve never seen one for Line before :wink: )

this is a little confusing for a mac user (well, it was for me)…
if that’s going to be the default shortcut in atom, you should write it
control-option-r (or control-opt-r) in the instructions…

generally when seeing ctrl-alt-x ,we’re trained to convert that from windows speak to mac speak which would be cmmd-opt-x

(like, ctrl to a mac user generally means use the command key… instead of the control key… the main reason i’m making an effort to lay this out is because in other translations between rhino & macrhino, we’re going to be seeing things like shift-ctrl for subObjectSelection equals shift-cmmd on mac… not shift-control)


on another note and not really related to the work you’re doing… does anybody know how to make atom open new files with python documents instead of .txt or whatever the default is… i guess you need to know a little coffeescript in order to customize? i suppose i can ask this at atom’s forum though.

I doubt we are going to be replacing the built-in editor any time soon. Our primary goal right now is to get some sort of editing/debugging capability on Mac Rhino for python scripts. As this feature improves with time we can add support for the Windows version of atom as an alternative editor.

This isn’t something that we are focused on at the moment. Right now we want to make sure that we can support an external editor like atom.


I think this is a huge step forward in supporting python scripting on Mac Rhino; thanks @Alain! Of course there is still a bunch of work to do to streamline the experience, and I am really excited to see where this goes. We wanted to get this out as soon as possible to try and get feedback from you guys on needed features and bugs that you may run across.

Getting an error while trying to install Autocomplete plus. Any way to do this manually, probably have more time to look after work. Screenshot and just updated to 175.

Thanks, Randy

looks like you need to install with admin privileges?

Possibly, it is a work computer. Works fine hère at home.

Cool, a starting point.

Thanks.

1 Like

hey Randy,
i think one of the better things about this so far is that you don’t need to have the file you’re working on in the scripts folder in order for it to run… (just pointing this out because of seeing the path in your screenshot and thought you might of assumed this was a requirement)… example.py can be on the desktop for instance and it will still run in rhino by way of atom.

what i hope to see happen eventually (and this might either A) already be possible or B) be more to do with something needing implemented in Atom) is:
launch a new file, it’s already python, and it saves to a temp location unless explicitly saved/named by the user…

that way, we open atom and start writing/running without needing to change to python and naming the document etc… in the same way you can launch rhino and start drawing immediately.


or another way to say that is- it’d be nice to be able to type in some code and run it without it needing to be tied to any particular file… or, if that’s going to pretty much be a requirement, then the file stuff happens behind the scenes unless we specifically want to deal with it in such a way.

Hey Jeff, thanks. It is out of habit and I have Scripts in my Finder sidéra, so easy to get to.

Some good points, need more time to use it for now.

Randy

Hi Jeff,

I forgot to note the Grow / Noticifation Center messages. That’s on our list of things to fix. Distracting I know but otherwise it shouldn’t cause problems.

As for the naming of the key bindings, it doesn’t come from windows speak but from Atom speak. In the beginning Atom was on osx only and was only released on Windows later. Press shift-cmd-p and type “keybindings” and have a look at the list. Because Atom is not embedded in Rhino I think it makes more sense to follow the Atom naming convention. The good thing is you can change the bindings if you don’t like them.

Thanks for the feedback.

Jeff, it seems to work like this. This morninf I opened a new Rhino file, Atom was running. I opened one of my scripts (in default folder), Background white. Press ctrl+alt+R and it runs.

Then open Background default and run it, voila! It runs.

I didm’t do anything in Rhino other than open it.

The following limitations are in effect right now though.

If I run this script, that calls for user input,

it runs, and since I know the script, I can still sélect the object and the script continues executing.


It is a gréât start,

Thanks McNeel team … Randy

Yes, since it’s just a screen refresh issue the script should still work.
Thanks for the feedback.

Notice this, rhino-python dépréciation.

Just to say.

Randy

yep, i see what you’re saying… it looks like atom is naming a lot of stuff in ways which aren’t specific to mac (backspace/enter/alt would generally be written delete/return/opt on a mac only app)…
but i get your point and agree… the application we’re talking about is Atom so you should follow its naming conventions.


yeah, that would work as the script is already a file… i’m talking about a blank script though.

like in windows rhino, i think you just open the python editor and start typing/testing/running… you don’t have to create a file first in order to run anything… if working on a specific script, it’s not a big deal as you’re going to want it to be a file anyway… but if you just want to copy&paste a little piece of code from this forum or, say one of the example in the rhinoscript docs in order to test/learn, you’ll need a saved/named/located python file first in order to run it… it’s not a huge deal as you can just have a couple of playground python files saved somewhere and just use those for these purposes.

I was rereading your first post about this, just as leaving for work, so now I understand. Atom is a text editor first so maybe on the Atom forum, see if Atom’s default language can be set to Python. As a former web coder, I preferred to have it set to HTML or CSS, etc. Checking now.

Hi Alain,
Thanks! So far everything works like you’ve described.

I’ve also installed the Dash Package and use it with the Python Help as well the RhinoCommon DocSet @dan provides: RhinoCommon Dash Docset .

This already works better than on Windows :smile:

i had a bit of trouble overriding an existing keystroke (wanting to use cmmd-R)

here’s what i eventually got to work in the keymap.cson file

'.platform-darwin atom-text-editor':
  'cmd-r': 'rhino-python:saveAndRunInRhino'

then relaunch Atom… (you have to relaunch… the user file will be read last and it’s what allows you to override a default keybinding)

to get to that file (which might be easier to just go through the file structure?) i went:
Atom-> Preferences-> Keybindings

there’s a blue link ‘your keymap file’ at the top which will open keymap.cson.

(just posting this in case anyone wants to do similar)

does it make sense to anybody else to have a rhino command to run the script in atom?

the set up i used previously with xcode (which was a combination of applescripts, osx keyboard shortcuts, and rhino keyboard shortcuts) let me run the script regardless of if i were in rhino or xcode.

for instance, say you’ve typed some code in atom, you go into rhino to delete some geometry, run the new code right then… instead of needing to switch back to atom, runInRhino, which then switches back to rhino again.

i’m not sure if this type of integration is possible but if so, it’d be nice to have.

I think that makes sense. After a script is run from Atom, Rhino could remember that “last script” and run-run it with some sort of ReRunPythonScript command. @Alain, what do you think?