What is going wrong in this code?

import bpy

from mathutils import noise

#how many cubes you want to add on each axis
count = 100

for i in range (0,count):
for cube_instance in range(0,count):
x = 1
y = 1 + i
position = [x, y, 0]
H = 2
lacunarity = .5
octaves = 4
z = mathutils.noise.fractal(position, H, lacunarity, octaves, noise_basis=noise.types.STDPERLIN)
#z = 0
bpy.ops.mesh.primitive_cube_add(location=(x * cube_instance + 1,y,z))

I’m getting an error message on the line defining z as Perlin Noise.

Any help would be appreciated.

What is the error message?

Just the generic one: “Python script fail, look in console for now”. Then highlights the line starting with z = 0

There are a few extra things on that line. Try this:

z = noise.fractal(position, H, lacunarity, octaves, noise.types.STDPERLIN)
  • the command ‘from mathutils import noise’ means you’ll just use ‘noise’, not ‘mathutils.noise’
  • the error was ‘fractal() takes no keyword arguments’. I’d say that’s rather an error in the API, but removing ‘noise_basis=’ does the trick