# I'm trying to create a Mandelbulb in Blender 3.3.1 using the scripter. Zero errors but nothing happens when I run the code

Below is my current code. I get no errors, but when I run the code nothing happens. I'm not even sure everything is right, or when it works will it work how I want. Any feedback or suggestions are helpful. Overall the end result should be a nice looking 3D Mandelbulb with decently high detail, hundreds of thousands of faces are expected if not more.

Code:


import bpy
import numpy as np
import math

def mandelbulb(x, y, z, iterations):
c = x + y*1j + z*1j
z = c
r = 0
for i in range(iterations):
r2 = x*x + y*y + z*z
if r2 > 2:
return i/iterations
theta = math.atan2(math.sqrt(x*x + y*y), z)
phi = math.atan2(y, x)
r = r2**(1/8)
x = r * math.sin(theta/8) * math.cos(phi/8) + c.real
y = r * math.sin(theta/8) * math.sin(phi/8) + c.imag
z = r * math.cos(theta/8)
return 0

def generate_mesh(size, iterations):
vertices = []
faces = []
for x in np.linspace(-2, 2, size):
for y in np.linspace(-2, 2, size):
for z in np.linspace(-2, 2, size):
value = mandelbulb(x, y, z, iterations)
if value > 0:
vertices.append((x, y, z))
return vertices, faces

def create_mesh_object(vertices, faces, name):
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(vertices, [], faces)
mesh.update()
object = bpy.data.objects.new(name, mesh)

def execute(size, iterations):
vertices, faces = generate_mesh(size, iterations)
create_mesh_object(vertices, faces, "Mandelbulb")

class MandelbulbOperator(bpy.types.Operator):
bl_idname = "object.mandelbulb_operator"
bl_label = "Mandelbulb Operator"
bl_options = {'REGISTER', 'UNDO'}

size = bpy.props.IntProperty(
name="Size",
default=32,
min=1,
max=256,
step=1,
precision=0
)
iterations = bpy.props.IntProperty(
name="Iterations",
default=64,
min=1,
max=512,
step=1,
precision=0
)

def execute(self, context):
execute(self.size, self.iterations)
return {'FINISHED'}

def draw(self, context):
layout = self.layout
layout.label(text="Create a 3D Mandelbulb")
layout.prop(self, "size")
layout.prop(self, "iterations")

def register():
bpy.utils.register_class(MandelbulbOperator)

def unregister():
bpy.utils.unregister_class(MandelbulbOperator)

if __name__ == "__main__":
register()

$$$$

• Just a hint: The script registers an operator. You need to run the operator so that the script actually does something. Run the script, then press F3, and search for "Mandelbulb Operator". The execute() method will then run. But there is a problem with the Size property and there will be an error :-( Need to have a closer look to solve it. Jan 30, 2023 at 4:12
• @Blunder I just tried the F3 and it seems like it can't find "Mandelbulb Operator" or any similar searches like "MandelbulbOperator" Jan 30, 2023 at 4:18
• Replace = with : in the operator properties definition (not those beiginng with bl_ + precision is an invalid argument for IntProperty, remove it in both size and iterations Jan 30, 2023 at 7:32

There are two little mistakes in your script as Gorgious wrote in the comments:

1. the operator properties "size" and "iterations" must be defined by ":" not by a "="
2. bpy.props.IntProperty has no precision parameter.
import bpy
import numpy as np
import math

def mandelbulb(x, y, z, iterations):
c = x + y*1j + z*1j
z = c
r = 0
for i in range(iterations):
r2 = x*x + y*y + z*z
if r2 > 2:
return i/iterations
theta = math.atan2(math.sqrt(x*x + y*y), z)
phi = math.atan2(y, x)
r = r2**(1/8)
x = r * math.sin(theta/8) * math.cos(phi/8) + c.real
y = r * math.sin(theta/8) * math.sin(phi/8) + c.imag
z = r * math.cos(theta/8)
return 0

def generate_mesh(size, iterations):
vertices = []
faces = []
for x in np.linspace(-2, 2, size):
for y in np.linspace(-2, 2, size):
for z in np.linspace(-2, 2, size):
value = mandelbulb(x, y, z, iterations)
if value > 0:
vertices.append((x, y, z))
return vertices, faces

def create_mesh_object(vertices, faces, name):
mesh = bpy.data.meshes.new(name)
mesh.from_pydata(vertices, [], faces)
mesh.update()
object = bpy.data.objects.new(name, mesh)

def execute(size, iterations):
vertices, faces = generate_mesh(size, iterations)
create_mesh_object(vertices, faces, "Mandelbulb")

class MandelbulbOperator(bpy.types.Operator):
bl_idname = "object.mandelbulb_operator"
bl_label = "Mandelbulb Operator"
bl_options = {'REGISTER', 'UNDO'}

size: bpy.props.IntProperty(
name="Size",
default=32,
min=1,
max=256,
step=1
)
iterations: bpy.props.IntProperty(
name="Iterations",
default=64,
min=1,
max=512,
step=1
)

def execute(self, context):
execute(self.size, self.iterations)
return {'FINISHED'}

def draw(self, context):
layout = self.layout
layout.label(text="Create a 3D Mandelbulb")
layout.prop(self, "size")
layout.prop(self, "iterations")

def register():
bpy.utils.register_class(MandelbulbOperator)

def unregister():
bpy.utils.unregister_class(MandelbulbOperator)

if __name__ == "__main__":
register()
`

After you run the script, no error should be displayed in the System Console window and nothing will happen because you only have registered the operator Mandelbulb Operator.

Use the main menu Edit > Menu Search... F3 or Edit > Operator Search... to find your operator. Both should work.