The Use of GPT Chat AI in Blender Code Creation

How to write code from 0 knowledge

Niko G.
3 min readJan 29, 2023
Blender and python

In this experiment, I aimed to explore the potential of GPT chat AI in creating code for the Blender program. The goal was to utilize code to create geometry in Blender, and see if the process could be made easier through the use of artificial intelligence.

print is also code

I must admit, I am far from being a proficient programmer, and even closer to being a novice. However, that did not discourage me from trying to utilize GPT chat AI in this experiment. I treated myself as a typical user who is unfamiliar with programming, and relied solely on the AI to generate code for me.

creating Cube in Blender by Python
Now asked to separate size parameters of Cube

The outcome was surprising. The code generated by the AI was consistently close to what I had requested, showcasing the AI’s ability to interpret my requests accurately. The key takeaway from this experiment is that you are no longer the one writing the code, but rather the operator who asks for the code to be written. The aim is to learn how to be an effective operator and to utilize the AI’s capabilities to your advantage.

now i asked rewite code. becose Z and Y direction is wrong

I attempted to challenge the AI by asking it to create more complex forms, such as creating a chamfer on a model. The result was successful, and the code generated by the AI was able to accomplish the task.

creating chamfer for out cube

In addition, I also asked the AI to simplify and make the code more concise. As a non-programmer, I cannot accurately judge the AI’s performance in this task. However, it is worth noting that the AI was able to provide a comprehensive explanation for each of its decisions and the working of the scripts. This feature is particularly useful for both beginners and experienced programmers, as it helps to understand the reasoning behind a particular decision.

I get error and GPT explaining whats wrong and refactoring code

The experiment was a resounding success, and I am pleased with the outcome. A full video of the experiment can be found below.

In conclusion, the use of GPT chat AI in Blender code creation has the potential to revolutionize the way we create code for programs like Blender. The AI’s ability to interpret and execute requests accurately, as well as its capacity to explain its decisions, make it a valuable tool for both beginners and experienced programmers.

import bpy

WIDTH = 10
HEIGHT = 40
LENGTH = 10
CHAMFER = 0.05

class Cube:
def __init__(self, width=WIDTH, length=LENGTH, height=HEIGHT, chamfer=CHAMFER):
self.width = width
self.length = length
self.height = height
self.chamfer = chamfer

def create(self):
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, 0))
cube = bpy.context.object
cube.scale = (self.width, self.length, self.height)
cube.location[2] = self.height / 2

cube.select_set(state=True)
bpy.ops.object.editmode_toggle()
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.bevel(offset=self.chamfer, segments=1, profile=0.5)
bpy.ops.object.editmode_toggle()
cube.select_set(state=False)

cube = Cube()
cube.create()

You can watch the full video of my experiment with GPT chat AI and Blender on here:

--

--