I’ve found a way to run Python scripts from PyCharm in Rhino for Mac.
CAVEAT: This is a hack. It may not work in the future. McNeel has provided us a way to run Python scripts in Rhino from Atom. It’s currently implemented with a REST API, but McNeel has not publicly documented the API or made any promises that it won’t change or that it will even continue to exist.
That said, the following is currently working for me:
Create an External Tool in PyCharm.
In PyCharm, open Preferences, and go to Tools > External Tools. Click the Add (+) button. The Create Tool dialog opens.
In the Name field, enter something like “Run In Rhino”. In the Program field, enter the following:
curl
In the Parameters field, enter the following
-d {\"FileName\":\"$FilePath$\"} http://localhost:8080/runpythonscriptfile
Leave all other fields at defaults. Click OK.
I’m running PyCharm 4.5.3 and Rhino for Mac version 5.0.2 (5A865) on Yosemite 10.10.5 (Build 14F27).
Run a Python script.
In Rhino, make sure the Atom Editor Listener is running. In PyCharm, open a .py file that contains a script you’ve written to run in Rhino. Make sure it’s the active file (i.e. it’s visible in the editor and its tab is highlighted). Right-click anywhere in the editor, and in the context menu, under External Tools, click the name you entered in the Create Tool dialog. A console should open. If you’re lucky, the stuff in the console will include this:
{"msg":"Successfully ran script"}
Bonus points: Add a button.
In the PyCharm toolbar, right-click and select Customize Menus and Toolbars… In the dialog that opens, expand Main Toolbar. Click the last item in the sub-list under Main Toolbar to highlight it. Click Add Separator. It will add a separator after the last item. Click the separator to highlight it. Click Add After… In the dialog that opens, expand External Tools and select the name you entered in the Create Tool dialog. Click OK. It will complain about not having an icon; just accept the default icon. (If you can figure out how to put the Rhino logo on the icon, post it here!) Now you should have a button at the end of your toolbar that runs your script in Rhino.