0
$\begingroup$

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.

$\endgroup$
2

1 Answer 1

3
$\begingroup$

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
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .