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

So your in Atom, probably changing the code to not effect the geometry you will delete in Rhino in Step 2. Switch to Rhino to delete the geometry … and then “run a command to execute the Atom script”, probably a macro / alias key-stroke.

As long as the script is saved and linked to a shortcut, we can do something similar now with RunPythonScript. The issue is a new script not linked to a key+stroke.

@stevebaer is quick and like he says, you could just hit spacebar to run last command.

for sake of discussion, say your script has something random in it… and you’d like to run it multiple times to get a visually appealing outcome… in rhino, it’d basically be: run it, delete or undo… run it again etc… currently, there’s a lot of app switching in order to do something like that… same goes for testing a script with different input objects or parameters… if i want to try the script on a straight line, then on a curve… it would be good if i could stay in rhino in order to do that instead of continually needing to switch back to atom.


taking it a step further (and i don’t know if i have a good case for arguing this ability other than i found myself doing it a lot with the xcode setup i had)… would be:

• there’s unsaved code in atom (well the working file is still myPyPlaground.py (or whatever))
• from rhino, i can trigger atom to save that code and run it in rhino.

basically what i’m getting at is if your shortcut in Atom is cmmd-R for save and run in rhino… and you also have a shortcut in rhino cmmd-R set to this requested command… you can push cmmd-R in either application and they both do the same exact thing from a user point of view… they run the code which is currently in the atom workspace regardless of it being saved yet or not.

it eliminates the user’s need to pay attention to which application is frontmost and/or which saved state the current script is in.


ADD… on a side note, this capability is possible to gain from osx services… but for whatever reason, rhino doesn’t have services enabled in the Rhinoceros menu (and i don’t know of another mac application which doesn’t have it hooked up… it may just be an oversight)… so maybe i should just make that request instead :wink:

Re running the script from Rhino sounds like a good idea.

I’m not sure about saving the script in Atom from Rhino. For one thing it wouldn’t be as easy to implement. One of the design goals is to have as little code in Atom as possible and most of it in Rhino in case we decide to support another editor. If the script has been modified it means you were just in Atom so remembering to save before switching back to Rhino sounds reasonable. There’s also an autosave Atom package that saves the document when Atom looses focus.

1 Like

that sounds good in and of itself.

currently, we can’t re-run a python script even if it’s being run from the RunPythonScript command… only the RunPythonScript command will be repeated instead of the script itself… so repeating a script currently consists of navigating to said script etc.

and yeah, i understand that you all would rather not make this more complicated than necessary… i think i can find ways within osx itself to get the other capability i was asking for… it can be complicated on my end without fussing things up for everybody :wink:

oh… ok, cool… that will probably help me out then… another editor i tried before called chocolat had that as a preference and it worked well (if you had a script in the scripts folder with a rhino shortcut assigned to running that exact script).

thanks for the input.

Hello Alain,

Thanks for this exciting update. I’ve run into trouble when I try to execute the scripts from ATOM, with this new Rhino build. There error is an exception error. snapshot below, not sure if others are running into the same problem?

I’ve tried to reinstall the Python plugin but still have this same error?
Thanks for your suggestions.

Omri

the necessary ironpython is including in rhino for mac these days (the past few months) so you don’t have to install anything other than rhino to run scripts.

what version of osx do you have?
also, open terminal.app (Applications-> Utilities-> Terminal)… type python …press return

what does it say for the python version number? (it will say something like Python 2.7.6)

Jeff,

Thanks for the response, i’m running python 2.7.2

now I’m getting a new error?

and it seems that the iron python version appears in the info box, which before when I did the new install it was showing no version.

Once I run ATOM and have Rhino listening for the scripts I also get this new error in the command line:

Command: StartAtomEditorListener
Directory ‘/Users/omrimenashe/Library/Application Support/McNeel/Rhinoceros/MacPlugIns/IronPython/settings/lib’ not found.

yeah, i think you’re experiencing the same issue that a few other people were having with osx10.8 (something about rhino not properly locating the python libraries)

there’s a fix in the last post of that :point_up_2: thread by randy which entails upgrading python (i believe you can go up to the highest 2.7.x now and be ok… someone else tried python 3.x and had problems with it)

(likewise, you could just upgrade to yosemite and everything should work but i understand you may have reasons for staying on mountain lion)

Thanks, I’ll give it a shot and see how that goes. Hopefully it’ll solve it.

Python Version 2.7.9 - makes the difference. It’s all running smoothly now :smile:

1 Like

Open up Xcode, and accept the new user agreement. This was happening because a new version of Xcode was downloaded and the new agreement was not accepted.

found the solution here: http://stackoverflow.com/questions/26197347/agreeing-to-the-xcode-ios-license-requires-admin-privileges-please-re-run-as-r

so the latest mac rhino build (5A683) has Services enabled via the rhinoceros menu… i was able to get the functionality i was asking about via an automator workflow… (ie- i can now trigger a script in atom via the same keystroke in either rhino or atom and the saved state of the .py doesn’t matter)…

i’ll post what i did a little later incase anybody else would like to use a setup like this.


regardless, thanks for getting this stuff working… it’s now a lot better than what i was doing previously with xcode… for one, i think xcode is way too complex if just wanting to write python scripts… plus there was no python auto indenting and obviously no rhino autocomplete in there.

one question- is there any harm or other things to be aware of if leaving the atom listener on? we don’t have startup actions in mac rhino but i do have a start up macro which i run when launching rhino (for things like Round points and setting volume to yards)… i was thinking of adding the atom listener to this macro or would it be better to just use it on an as needed basis and turn it off when finished?
thanks

There “shouldn’t” be any harm, but this is still under early development so it is hard to guarantee that:)

ha. ok
i’ll guinea pig it. :wink:

(i mean, i’ve left it on for long amounts of time so far with no perceivable ill effects… so i’ll just keep doing that and report if i come across anything not-so-good)

I’m interested - haven’t done any apple script for a long time…

I’m, also interested. Would love to see AppleScript usability with Rhino.

@jess @rhinorudi i have a meeting this morning but i’ll put something up when i get back.

it’s not incredibly exciting -or- rhino itself isn’t applescript_able… it’s just some basic GUI scripting via applescript and automator.app … but yeah, give me a few hours and i’ll put up some screenshots/instructions

@jeff_hammond, thanks. And.
No rush, design meeting day for me as well.
Randy

When I’m using a custom editor on windows I have a shortcut which puts a -_RunPythonScript macro with the path to the current script to the clipboard. Then I can paste in Rhino to run that script, and of course also repeat this as the last command. I assume this should be possible with Atom as well. Have to check this…

that’s sort of what i was doing before… or, i had a few macros which would run specific scripts and i’d keep those scripts strictly for writing with then duplicate/save as their actual name once completed… the thing i maybe like most about this atom listener thing is that you don’t have to tell rhino which exact script to run… it will simply run whichever file is active in atom.


anyway, here’s my setup right now.

in Atom, i’ve assigned ⌘R to ‘saveAndRunInRhino’ by editing the keymap.cson file (as shown earlier in the thread)

…so if i’m in Atom, i push ⌘R and the current script saves then runs in rhino.



in automator.app, start a new document and choose Service as the type:



then build the service as seen below:

  1. the service is to receive no input and only for the application rhinoceros

  2. for the action, use Run AppleScript and enter the code shown in the picture…

all it’s doing is telling Atom to come to the front then it keystrokes ⌘R (which is the keystroke i set for saveAndRunInRhino)… so when i run this service from rhino, it switches to atom, saves the current file, then runs it in rhino… it may be disorienting with the quick app switching that is happening but if your display is large enough to fit atom next to rhino instead of on top of it, you’ll barely notice the switching…



i saved the Service as to_Atom and that now shows up in the rhino services menu (you need the latest mac rhino to do this (5A683)+



you’ll see the service also has a keystroke ⌘R assigned which is done in System Preferences-> Keyboard-> Shortcuts-> App Shortcuts



so now, i can press ⌘R in either rhino or atom… in either instance, the current python file in atom will run in rhino and any saving that may be needed will be done automatically…

in the future, if a re-run Python script is added to rhino, this might be a little less confusing to get working this way (using the atom package which saves the file when atom loses focus)

1 Like