Hi everyone,
I often rely on AI-generated Python code to tidy up and develop scripts for ghpython nodes in Grasshopper for Rhino 3D (v8). While this works well for simpler tasks, I’m not an expert in Python, so when things get more complex—especially with data structures like trees—I’ve noticed that the prompts I use don’t always generate the desired results.
Here’s a common example of how I structure my prompts:
You are an expert Python3 programmer. Write a Python 3 script (uses CPython) for a ghpython node in Grasshopper for Rhino 3D 8, with the RhinoCommon 8.0 API and the RhinoScriptSyntax API and Python library, .NET functionality.
- Add a descriptive message for this Grasshopper component by using ghenv.Component.NickName with the prefix 'Py3_'.
- Name Grasshopper parameters and variables by PEP 8 convention (lower_case_with_underscores)."
Create a script or modify the code pasted below if provided with the following requirements:
However, when handling more complex inputs (like data trees), the AI-generated code sometimes doesn’t handle the structures properly, leading to errors. Additionally, it’s difficult to copy/paste complex data structures into the AI prompt, as they often get flattened into text, which distorts the structure making it hard to debug. I’m sure many of you have faced similar issues!
Yes, I know learning to code is step one, but AI can be a helpful assistant along the way to streamline the process or provide additional support.
So, I’m asking:
What kind of prompts or strategies do you use to generate accurate AI-assisted Python or C# code for Grasshopper, especially for complex data structures?
The goal of this thread is to gather insights on what works best for improving the accuracy of AI-generated code.
If you have any useful prompts, tips, or experiences to share, I’d really appreciate it!