Rhinocommon development environment for Python

I am currently putting together a little plugin with the Rhinocommon api and Python, however I cannot seem to find a decent dev environment setup. I have currently resorted to copy pasting my code into the script editor in Rhino 7 and running it from there to test stuff. This get quite tedious especially when importing modules and having the file open in VS Code at the same time. (Also having a nightmare of a time trying to get the rhino stubs to work with pylance for some reason)

So I was wondering what other people’s setups look like. Has anyone got a streamlined workflow that allows for quick testing when developing for rhino in python?

I assume this is much more straightforward if using C# and Visual Studio but unfortunately my programming language knowledge is limited to Python.

I got something working for RhinoPython by following the general plug-in guidance, and using yak. Packaging was tricky though, and felt like I may as well use C#. There was still a manual step with the RhinoScriptCompiler menu navigation, and the tooling was particular about fresh version numbers. It could compile Iron Python to .Net though.

I’m more familiar with Grasshopper. I wouldn’t describe what I do as streamlined, but in development, hot reloading of Python code can be achieved. To iterate without restarting Rhino, I work on open source plug-ins with launcher components. These launchers import all my code in a package. I also have an extra Python component in dev, that essentially just runs del sys.modules['package_name'] (I iterate over all sub module names too). After making a change to the code, I run that, then hit F5 to recompute the whole Grasshopper worksheet (assuming the path to the dev repo package is in sys.path). The first launcher to run, will be unable to find a cached version of the package, and will re-import it, along with the latest changes. This is a bit like using reload in Python 2, which can be buggy.

If using CPython3 components in Rhino 8, the Python.exe and pip run-times can be found. I’d try using those to do an editable install of my plug-in’s Python package’s dev repo (pip install -e)

1 Like