Hello everybody. I need a script that add many cubes in a random location with a random scale. if possible after that, all the cubes should become a single mesh.
Thanks
I guess you could use a particle system for that, but here’s a bmesh module solution:
import bpy
import bmesh
from random import uniform
from mathutils import Matrix
bm = bmesh.new()
for i in range(300):
mat = Matrix.Translation((uniform(-10, 10), uniform(-10, 10), uniform(-5, 5)))
bmesh.ops.create_cube(bm, size=uniform(0.1, 2.5), matrix=mat)
me = bpy.data.meshes.new("Cubes")
bm.to_mesh(me)
ob = bpy.data.objects.new("Cubes", me)
scene = bpy.context.scene
scene.objects.link(ob)
scene.update()
and if i want to add a metaball?
its great. but how i can add, with this script, the meshs that i want ?
ex: “metaball”-“cylinder”-etc…
there are several bmesh.ops for primitives:
metaballs are a complete different type of object (not mesh), you need a pretty different script for that (create individual metaball objects, select, convert to mesh and join).
ok thanks you