Steve Baer at McNeel posted on the McNeel forum about the Python package Rhino-Stubs he had created and how to use it in PyCharm for autocompletion and type hints for Rhino/Grasshopper scripts. Here’s the thread and here’s the full explanation on Steve’s blog.
I’ve started to write a lot of Python scripts in Grasshopper which usually means you write using the built in editor if you want autocompletion. Since I already copy my scripts to a git repository for version control I jumped at the chance to do more of the scripting in an external editor. While PyCharm has an OK Vim plugin I still longed for the comfort of trusty Vim.
The Rhino-Stubs package provides Python stubs as described in PEP-484 and PEP-561, and my initial research led me to an issue on the jedi repository (a widely used autocompletion engine for python). However, I also found another source of stubs, gtalarico/ironpython-stubs in another format. The repo’s wiki includes instructions for integration with Atom, VS Code and Sublime Code, and I used these instructions to integrate the stubs with Vim and Jedi through vim-jedi.
Here are the steps needed in case someone else wants to try it.
These instructions assumes that you have a Linux environment with an installation of Vim that has been compiled with python support, and that you have Python 2 installed. Other autocompletion plugins might interfere with jedi-vim, disable them if you are having trouble.
- Install the Vim plugin jedi-vim.
- Clone or download gtalarico/ironpython-stubs. The repo will be referenced in the next steps.
- Append the path to the stubs to the
PYTHONPATHvariable in your shell profile (e.g.
.bash_profile/.bashrc/.zshrc) using the command
let g:jedi-vim#force_py_version = '2'in your
.vimrcif you have Python 3 in your environment.
- Create a new virtualenv with the command
virtualenv -p python2 my_ironpy_scripts. Replace python2 with the path to your Python 2 executable if python2 doesn’t work.
- Create a file called
my_ironpy_scripts/lib/python2.X/site-packages/containing the absolute or relative path to the ironpython-stubs. E.g.
source bin/activateand start editing, jedi-vim will use your virtualenv with the added path to the stubs.
You are now ready to complete using jedi-vim, the standard keymap is
<C>-<Space>. I use ervandew/supertab to map completions to
I’ve tried to use the same method with the stubs provided by Rhino-Stubs, but haven’t gotten it to work. If someone figures it out, please let me know. This would be interesting because Rhino-Stubs provides better support for RhinoInside.