I'm interested in using a 3D authoring tool to generate structures algorithmically, and since Blender provides a python API i wanted to give it a try.
I managed to create a grid of cubes with different dimensions and rotations using this script:
Code: Select all
from random import randrange import random import bpy add_cube = bpy.ops.mesh.primitive_cube_add mylayers = [False]*20 mylayers = True for indexX in range(0, 10): for indexY in range(0, 10): for indexZ in range(0, 10): location = indexX, indexY, indexZ rotation = randrange(-10,10), randrange(-10,10), randrange(-10,10) dimensions = random.random(), random.random(), random.random() cube = add_cube(location=(location), rotation=(rotation), layers=mylayers) cube = bpy.context.object cube.dimensions = dimensions
It generates the cubes as expected, but it takes A LOT of time to do so (about 30 seconds). Is it normal to take this long? (I'm not refering to rendering but to the actual objects creation).
BTW, I'm using the nested loops for simplicity, but I have the same problem (regarding execution time) if i use a single loop and, let's say, random positions.