Search code examples
pythonfor-loopnested-loopsblender

How to increase the value of y by one every time on this loop


I am doing some basic Python in Blender and I want to add in a grid of cubes. If you can imagine that as count is 5 this creates a 5x5 grid of 25 cubes. However, I've got the code working so that the x axis increases each time but don't know how to edit the nested for loop so it does the same and increases along the y, as at the moment all that happens is you get a 5-long line of cubes with 5 more cubes layered on top of it.

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

for i in range (0,count):
    for cube_instance in range(0,count):
        x = 1
        y = 1
        z = 0
        bpy.ops.mesh.primitive_cube_add(location=(x * cube_instance + 1,y,z))

Thanks for any help.


Solution

  • I'm guessing y = 1 + i should do the trick.