Autocomplete while editing python scripts outside of Rhino

Here’s a way to get autocomplete on both Windows and Mac for editing python scripts that use RhinoCommon and Grasshopper.

6 Likes

Works nicely! If anyone figures out a way to get this working in Vim, please let me know ;).

It seems similar to denfromufa/ironpython-stubs, have you tried it?

To be fair, that is a fork of Gui’s work at https://github.com/gtalarico/ironpython-stubs

I have looked at those packages and they are very nice. The issue with them is that they are mock libraries so it is very hard to actually run a python script for Rhino with those libraries on your python search path. The stub files that I created follow the guidelines of some recent python PEPs so hopefully support will show up in other editors over time as this is a standard.

A big advantage of using these stub files is that you can use them in combination with the new rhinosinside package discussed here:


I am hoping to write another article about this use case soon.

2 Likes

Hi Steve,
That github repo included instructions for using stubs with other editors (atom, sublime and vs code) . I don’t know if they have the limitation you describe

I used them by simply adding them to my project path in Pycharm so I could get edit more comfortably with autocomplete, for later execution within Rhino.
I also set up pycharm for Python 2.7 compatibility

They will. Don’t get me wrong, the stubs approach that Gui wrote works great with the exception of actually running and debugging your python script in the editor. Most of the time that isn’t actually possible so it doesn’t matter. With the new rhinoinside package this all changes.

Hmm not sure - the instructions refer specifically to the Jedi autocomplete engine, not the site packages folder or Python path but like I say, I haven’t tried :woozy_face:

I apologize, I do think I was wrong. It looks like the stubs are added as an extra location in the editor and not part of the standard python path.

Would it be possible to add some kind of scriptcontext proxy in the stubs? So we can import scriptcontext and can get to a proxy document, and everything still work when we run in Rhino?

Or maybe there is some other way to import the scriptcontext that will work in both environments? I tried a couple thoughts but none panned out.

I have after some work gotten gtalarico/ironpython-stubs to work in Vim. I have tried but not succeeded in getting the Rhino-Packages to work however.

Here are the steps in case someone else prefers working in Vim. 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 python2 installed. Other completion plugins might interefere with jedi-vim.

  1. Install Vim plugin davidhalter/jedi-vim using your prefered method.
  2. Clone or download gtalarico/ironpython-stubs. The repo will be referenced in the next step.
  3. Append the path to the stubs to the PYTHONPATH variable in your shell profile (.bash_profile/.bashrc/.zshrc) using the command export PYTHONPATH=${PYTHONPATH}:/path/to/iron-python-stubs/release/stubs.min
  4. Put let g:jedi-vim#force_py_version = '2' in your .vimrc if you have python3 in your environment.
  5. You are now ready to complete using jedi-vim, the standard keymap is <C>-<Space>. I use ervandew/supertab to map completions to <Tab>.

As I said, I’ve tried to use this method to complete with Rhino-Stubs. I tried installing the package using pip2 and adding the path to the relevant site-packages directory but for some reason jedi-vim doesn’t complete Rhino methods.

Edit: I wrote this up with some more context on my blog and I have opened an issue to have it added to the ironpython-stubs wiki.

1 Like

Well done! Hmm maybe I should do the same for Pycharm :thinking:

Why not use @stevebaer’s python package if you are using PyCharm?

Yes good point. I have recently changed computer and I haven’t yet set up Pycharm so I’ll now give that a go. I might write up the stubs process for others as well … after my holidays :sunglasses:

1 Like