0

What is the fastest way to create an array of objects through a script? I want to create a cube made from 10x10 rows of smaller cubes. So far my methods have been too long.

Ray Mairlot
  • 29,192
  • 11
  • 103
  • 125
Jenny
  • 53
  • 4

1 Answers1

3

Add a cube, then apply an array modifier in each dimension, and finally separate each part.

import bpy

bpy.ops.mesh.primitive_cube_add(enter_editmode=False, location=(0, 0, 0))
cube = bpy.context.selected_objects[0]
dimensions = [10, 10, 10]  # Rows, Columns, Levels

for i in range(3):
    mod = cube.modifiers.new('Array', 'ARRAY')
    mod.relative_offset_displace[0] = 0
    mod.relative_offset_displace[i] = 1.1
    mod.count = dimensions[i]
    bpy.ops.object.modifier_apply(modifier='Array')
bpy.ops.mesh.separate(type='LOOSE')  # Remove this line to keep all cubes in one object
Gorgious
  • 30,723
  • 2
  • 44
  • 101