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.
Asked
Active
Viewed 1,030 times
0
-
3Hi. What do you mean by "So far my methods have been too long"? Can you show what you've tried so far? Thanks. – Ray Mairlot Apr 01 '20 at 14:19
-
2Related https://blender.stackexchange.com/a/61254/15543 – batFINGER Apr 01 '20 at 15:29
1 Answers
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