@rickyblender, I didn’t have any issues with the script. Not sure what you’re doing wrong but worked perfectly for me.
@Dune2k, Cool script! I made a couple really simple changes to the script in #18, hope you don’t mind!
Nothing big, now works on any selected object (don’t need to rename it to “six”). And instead of duplicating the object, I changed bpy.ops.object.duplicate_move -> bpy.ops.object.duplicate_move_linked which creates and instance of the original object instead of a copy. That way you can change the shape of the original object and the rest change as well. Might be useful for motion graphics stuff I’ve been working on!
# Select the "six" object and duplicate it like a formula!
# Dune2k / Lars 2012
import bpy
from math import *
tau = 2*pi
the_object = bpy.context.active_object.name
if bpy.data.objects[the_object].select:
six_len = (3**.5) # x-size of hexagon
total = 20 # amount of steps (>40 will make PC crawl for a while)
max_value = 2*tau # max value for formula (>tau is sea effect)
steps = max_value/total
scaler = 1 # scale formula (not used)
for q in range(0,total):
bpy.ops.object.select_all()
bpy.data.objects[the_object].select = True
for i in range(0,total):
bpy.ops.object.select_all()
bpy.data.objects[the_object].select = True
if (-1)**q < 0:
x = six_len/2+six_len*i
else:
x = six_len*i
y = q*1.5
z = sin(steps*i)+sin(steps*q)
bpy.ops.object.duplicate_move_linked(TRANSFORM_OT_translate={"value":(x,y,z)})
@Rickyblender,
You get the error because the script requires you to have two materials with names. You can easily just make it create random materials and assign them like this.
import bpy, math, random
rows = 12
steps = math.pi/rows
mat1 = bpy.data.materials.new("Mat1")
mat1.diffuse_color = (random.random(), random.random(), random.random())
mat2 = bpy.data.materials.new("Mat2")
mat2.diffuse_color = (random.random(), random.random(), random.random())
for y in range(0,rows):
for x in range(0,rows):
### setting up box stuff
bpy.ops.mesh.primitive_cube_add(location= (x*steps,y*steps,0) )
bpy.context.scene.cursor_location = bpy.context.active_object.location
bpy.context.scene.cursor_location.z -= 1
bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
### determining boxes
bpy.context.active_object.scale.x = steps/3 # change for space between cubes
bpy.context.active_object.scale.y = steps/3
## the formula:
bpy.context.active_object.scale.z = (math.exp((x*steps))+math.exp((y*steps)))*.1
bpy.ops.object.material_slot_add()
a = x
if (-1)**y <= 0:
a += 1
if (-1)**a <= 0:
bpy.context.active_object.material_slots[0].material = mat1
else:
bpy.context.active_object.material_slots[0].material = mat2