ChatGPT and RhinoCommon

There has been a lot of buzz around ChatGPT since it was released end of last year. In short, ChatGPT is a smart chatbot that can generate text provided user input from a prompt. While this might not be a revolutionary concept, what’s new is the quality of its response, and that the Chatbot is very good at understanding conversational context.

Discussions on social media about how ChatGPT will revolutionize every industry have been hard to miss. For example, you can ask it to write a blog post given a specific topic, or to find errors in a code snippet.

I have personally been interested in understanding how this can be used to automate tasks in computational design and AEC (architecture, engineering, construction). As we often build systems and write code that generates building geometry, I wanted to see if the Chatbot could do something along those lines.

So I asked it to generate a parametric model of the One World Trade Center tower (OWTC) in NYC. As Rhino & Grasshopper is my preferred choice of weapon, I specified that I’d like a snippet of C# code using the RhinoCommon SDK. Here’s the prompt I used:

Using the RhinoCommon C# SDK for Rhino 7, can you please write a static C# method that generates a mesh that looks like the One World Trade Center building in NYC? Please write it in such way that I can easily paste it into a C# scripting component in Grasshopper. Do not include namespace declarations, the using scope or the class scope. Just the method is fine.

Here’s the response I got (sorry for the low quality).

At a first glance I was very impressed:

  • The C# code seems valid, including its usage of Rhinocommon.
  • It clearly understands what the OWTC is and what it looks like. For example, the height 541.3 m defined as the Z value in the top point seems to correlate well with the information in the Wikipedia article.

So I pasted this into a C# scripting component, which immediately gave me compile errors and upon closer inspection it was quite evident why:

The Mesh.CreateFromLoft method doesn’t exist! It completely made that up.

However, CreateFromLoft does exist for the Brep type. So I thought it might give me better stuff if I instead of specifying Mesh output specify Brep output. I did this, and got some new code which I pasted back into a scripting component i Grasshopper:

It does compile now, but the output looks quite odd. Looking into ChatGPT’s code, it does the following:

  • Defines points for the top and bottom rectangles.
  • Creates the facade surfaces.
  • Converts the surfaces to Breps.
  • Finally joins all the Brep parts into one unified Brep.

My suspicion was that the last Brep.JoinBreps operation could be reason why the output looks odd in case the join failed. So I got rid of this, and changed the output type to Brep[], instead of Brep. Here’s the result:

Better! Now if you squint, you might actually be able to see the shape of OWTC 🙂 I have no idea what the free floating facade surfaces are about, but it looks like ChatGPT extruded the vertical edges horizontally.

I stopped here, but could probably have kept on going and improved it by providing it with more feedback. My general impression is positive. I had very low expectations, so the fact that it gave me compile-ready RhinoCommon code is really cool.

So what’s next? Perhaps it would’ve been possible to improve the geometric output by refining my prompt message. The concept of getting ChatGPT to generate RhinoCommon code is really powerful. I think we’ll have to wait for a long time before we get code that generates detailed and accurate buildings that can be used in production. However, this might be a valuable approach for getting a starting point for a script which then can be improved manually.

I would love to see more examples of combining ChatGPT with Rhino/Grasshopper/RhinoCommon, so don’t hesitate to reach out if you know anything!

P.S. I wrote this article entirely by my self – no ChatGPT generated content 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s