Has anyone actually received working Grasshopper code from AI?

Hi everyone,

I am trying to build a Mesh Analyzer in Grasshopper using the new Rhino 8 Python 3 Script Editor. I am using Rhino 8.15. To speed up the process, I tasked Google’s Gemini AI with writing the script for me.

However, the code provided by Gemini completely fails, throwing a runtime error and turning the Grasshopper component bright red. It seems the AI heavily struggles with the new .NET/CPython 3 environment and keeps mixing it up with legacy IronPython (Rhino 7) workflows.

Before I give up on using AI for this entirely, I want to ask a broader question to the community:

Has anyone here successfully used Gemini or other AI assistants like Claude or ChatGPT, Copilot to generate working, error-free Python 3 scripts for Rhino 8 from scratch? Which AI model is actually capable of handling the Script Editor and its data binding without crashing the component?

Python3 AI_ gemini attempt.gh (17.9 KB)

I’ve used Claude more than once, but of course there are always errors in the code. It’s just that with Claude, it seems to me, they’re not that difficult to fix, and once you’ve got a relatively stable version, it’s much easier to continue.

-Robert

I’d like to give a couple of recommendations:

  1. I don’t know why, but it seems to me that he writes plugins in C# better than Python scripts.
  2. I use the $20 version of Claude. :slight_smile:

I have managed this using the RhinoMCP as it can open Rhino, load the GH plugin and debug it and keep trying. You’ll want to use a later version of Rhino 8 though, 8.15 is old :slight_smile:

I already have quite a small collection of scripts done with ChatGPT.
My problem is now about how to organize them, move some from one category to another - the UI of grasshopper is quite limited when it comes to rearranging components and modifying their properties.

@Balazs , if the script gives you an error, copy the error from the terminal to your AI and it will attempt to solve it or give you more information about it.

Also useful is to split a big problem into smaller parts.

Hey @Bogdan_Chipara have you given Runchat a go?

You can connect claude to run Rhino commands, write python scripts and create Grasshopper definitions (like the rhino mcp but a little simpler to set up), you get a script browser for all generated Rhino scripts that you can share, it knows how to create HTML UI and eto forms and there are some very cheap agents on there that are good for experimentation and playing around.

I use Grok. I’m able to ‘one-shot’ relatively simple stuff… sometimes… and usually debugging is quite simple. I’m just getting back into scripting so it took me awhile to remember things like type hints.

I’m sure if I did something more complex I would have to get into some real debugging. But it’s likely that I would save significant time still - the debugging ends up being about as much as if I had written the code myself. But now the code is generated in seconds/minutes.

It gets a few things wrong repeatedly which is annoying and seemingly impossible to avoid. The GetOneObject / GetObject "Result is always wrong but this is more to do with scripting outside GH. I’m sure I’ll encounter similar things but you just tell it and it usually sorts it out.

The legacy issues you’re speaking of are either due to using a really crappy AI version (free?). I don’t want to say that it might be your prompts because that’s victim blaming ;-). If you’re half decent at Python you should be able to steer the AI to Python 3 in a single prompt. I haven’t used Claude for a year but it was pretty bad (even the paid version) and would even revert back; remember though this was one year ago - paid but back when it was monthly not token based. Grok however gets it right away. Some of the issues above might be due to the older versions of RhinoCommon but given that the documentation is patchy and tons of code on Github doesn’t even work, it’s amazing it’s able to get as much as it does.