I get a puzzling result with my script:
for i in range(10):
if i % 2 == 0:
bpy.ops.mesh.primitive_cube_add()
else:
bpy.ops.mesh.primitive_uv_sphere_add()
bpy.context.active_object.location.y = i * 2
red_mat.diffuse_color = [1, 0, 0, 1]
blue_mat.diffuse_color = [0, 0, 1, 1]
cube_count = 1
sphere_count = 1
print("Cube " + str(cube_count))
cube_count += 1
else:
obj.name = f"Blue Sphere #{sphere_count}" print("Sphere " + str(sphere_count))
sphere_count += 1
This spits out the following print statements:
Cube 1
Cube 2
Cube 3
Cube 4
Cube 5
Cube 6
Cube 7
Cube 8
Cube 9
Cube 10
Cube 11
Cube 12
Cube 13
Cube 14
Sphere 1
Sphere 2
Sphere 3
Sphere 4
Sphere 5
There are only five cubes in the scene. Why does it go to 14?