Random piles boxes generator finished

This is my first script.

it creates columns of random sized boxes

You can choose the amount of boxes & the amount of columns

If you think about any improvement…
Say it !

the script is here :

http://www.pikilipita.com/blender/

Thanks! I made all kinds of things with your previous version so I’ll play with this one now.

%<

Hi pikilipita,

there was some talk of possibly adapting your script for city block creation in your previous post. Would this be a feasible option for the future?

Are the random variables able to be changed to a specific quantity? IE could I state that tower 1 should be 10 blocks high, the next 20 etc.

Good work. :smiley:

Sonix.

Well, somebody called Jimmy Haze sent me an update of my script,
but his e-mail : [email protected] doesn’t work.

Does someone know who’s this man ?

I’ll post his update as sson as i’ve deleted all the blank spaces at the end of each line…

blender 2.23#

#Press Alt + P to start the script

import Blender
from Blender import NMesh, BGL
from Blender.Draw import *
from random import randint, random

#################################

#################################

def lancer():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopex, slopey, slopez, vra, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(1)
piley = Create(1)
pilex = Create(1)

size of cubes

sizez = Create(1.0)
sizey = Create(1.0)
sizex = Create(1.0)

random cube size value

sizezra = Create(1.0)
sizeyra = Create(1.0)
sizexra = Create(1.0)

cubes/piles position

posz = Create(0.0)
posy = Create(1.0)
posx = Create(1.0)

random position value

poszra = Create(0.0)
posyra = Create(1.0)
posxra = Create(1.0)

slope

slopex = Create(0.0)
slopey = Create(0.0)
slopez = Create(0.0)

fun = Create(0.0)
funn = Create(0.0)
fnn = Create(0.0)
fuu = Create(0.0)

randomise vertices

vra = Create(0.0)

Register(gui, event, bevent)

################################

Preset1 : Piki-piles

################################

def preset1():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopex, slopey, slopez, vra, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(10)
piley = Create(4)
pilex = Create(4)

size of cubes

sizez = Create(1.0)
sizey = Create(1.0)
sizex = Create(1.0)

random cube size value

sizezra = Create(1.0)
sizeyra = Create(1.0)
sizexra = Create(1.0)

cubes/piles position

posz = Create(0.0)
posy = Create(8.0)
posx = Create(8.0)

random position value

poszra = Create(0.0)
posyra = Create(1.0)
posxra = Create(1.0)

slope

slopex = Create(0.0)
slopey = Create(0.0)
slopez = Create(0.0)

fun = Create(0.0)
funn = Create(0.0)
fnn = Create(0.0)
fuu = Create(0.0)

randomise vertices

vra = Create(0.0)

Register(gui, event, bevent)

##################################

Preset 2 : Random city

##################################

def preset2():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopex, slopey, slopez, vra, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(1)
piley = Create(8)
pilex = Create(8)

size of cubes

sizez = Create(4.0)
sizey = Create(2.0)
sizex = Create(2.0)

random cube size value

sizezra = Create(10.0)
sizeyra = Create(5.0)
sizexra = Create(5.0)

cubes/piles position

posz = Create(0.0)
posy = Create(12.50)
posx = Create(12.50)

random position value

poszra = Create(0.0)
posyra = Create(3.0)
posxra = Create(3.0)

slope

slopex = Create(0.0)
slopey = Create(0.0)
slopez = Create(0.4)
fun = Create(0.0)
funn = Create(0.0)

randomise vertices

vra = Create(0.0)

Register(gui, event, bevent)

#################################

Preset 3 : flat

#################################

def preset3():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(1)
piley = Create(4)
pilex = Create(4)

size of cubes

sizez = Create(0.25)
sizey = Create(10.0)
sizex = Create(10.0)

random cube size value

sizezra = Create(0.0)
sizeyra = Create(0.0)
sizexra = Create(0.0)

cubes/piles position

posz = Create(0.0)
posy = Create(4.0)
posx = Create(4.0)

random position value

poszra = Create(0.0)
posyra = Create(0.0)
posxra = Create(0.0)

slope

slopex = Create(0.0)
slopey = Create(0.0)
slopez = Create(0.0)

fun = Create(-0.4)
funn = Create(-0.4)
fnn = Create(0.0)
fuu = Create(-0.8)

randomise vertices

vra = Create(0.0)

Register(gui, event, bevent)

################################

Preset4 : Block

################################

def preset4():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, vra, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(3)
piley = Create(3)
pilex = Create(3)

size of cubes

sizez = Create(4.0)
sizey = Create(4.0)
sizex = Create(4.0)

random cube size value

sizezra = Create(1.0)
sizeyra = Create(1.0)
sizexra = Create(1.0)

cubes/piles position

posz = Create(0.0)
posy = Create(4.0)
posx = Create(4.0)

random position value

poszra = Create(0.0)
posyra = Create(0.0)
posxra = Create(0.0)

slope

slopex = Create(0.0)
slopey = Create(0.0)
slopez = Create(0.0)

fun = Create(0.0)
funn = Create(0.0)
fnn = Create(0.0)
fuu = Create(0.0)

randomise vertices

vra = Create(0.0)

Register(gui, event, bevent)

##################################

Preset 5 : Stair

##################################

def preset5():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, vra, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(1)
piley = Create(8)
pilex = Create(1)

size of cubes

sizez = Create(1.0)
sizey = Create(1.0)
sizex = Create(10.0)

random cube size value

sizezra = Create(0.0)
sizeyra = Create(0.0)
sizexra = Create(0.0)

cubes/piles position

posz = Create(0.0)
posy = Create(1.0)
posx = Create(1.0)

random position value

poszra = Create(0.0)
posyra = Create(0.0)
posxra = Create(0.0)

slope

slopex = Create(0.0)
slopey = Create(1.0)
slopez = Create(0.0)

fun = Create(0.0)
funn = Create(0.0)
fnn = Create(0.0)
fuu = Create(0.0)

randomise vertices

vra = Create(0.0)

Register(gui, event, bevent)

#################################

Preset 6 : Wall

#################################

def preset6():
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey,slopex, slopez, vra, fun, funn, fnn, fuu

amount of cubes/piles

pilez = Create(6)
piley = Create(1)
pilex = Create(9)

size of cubes

sizez = Create(1.5)
sizey = Create(1.5)
sizex = Create(2.5)

random cube size value

sizezra = Create(1.5)
sizeyra = Create(1.5)
sizexra = Create(1.5)

cubes/piles position

posz = Create(0.0)
posy = Create(3.0)
posx = Create(3.0)

random position value

poszra = Create(0.0)
posyra = Create(0.0)
posxra = Create(0.0)

slope

slopex = Create(0.0)
slopey = Create(0.0)
slopez = Create(0.0)

fun = Create(0.0)
funn = Create(0.0)
fnn = Create(0.0)
fuu = Create(0.0)

randomise vertices

vra = Create(0.2)

Register(gui, event, bevent)

###############################

Function

###############################

#oriz = 0
#ha = 0
#orixx = 0
#oriyy = 0

#######

def create(pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, vra, fun, funn, fnn, fuu):
# ####### #
for iaa in range (0,piley.val,1):
oriyy = posy.valiaa
for ia in range (0,pilex.val,1):
orixx= posx.val
ia

  oriz=posz.val
  ha=0 + poszra.val*random()

  for i in range (1,pilez.val+1,1):
   oriz= oriz+ha

#######################################################################################################

you can change the order of the “ia-iaa” to get diverent results (also all other parameters)#######

############################ ####### ####### ######## ####################
lo = sizex.val+fun.valiaaiaa+funn.valiaia+fnn.valiaaia+fuu.valiaaiaa+sizexra.valrandom()
la = sizey.val+fun.val
iaaiaa+funn.valiaia+fnn.valiaaia+fuu.valiaia+sizeyra.valrandom()
ha = slopez.valiaiaa+slopex.valia+slopey.valiaa+sizez.val+sizezra.val*random()

   orix = orixx + posxra.val*random()
   oriy = oriyy + posyra.val*random()


   me= NMesh.GetRaw()
   # drapeau indiquant qu'il n'y a pas de uvmapping
   #me.has_uvco=0
   # drapeau indiquant que les faces ne sont pas coloriées 
   #me.has_col=0

   #0 1 2 3 
   v=NMesh.Vert(orix+vra.val,oriy+vra.val,oriz+vra.val)
   me.verts.append(v)
   v=NMesh.Vert(orix+vra.val,oriy+la+vra.val,oriz+vra.val)
   me.verts.append(v)
   v=NMesh.Vert(orix+lo+vra.val,oriy+la+vra.val,oriz+vra.val)
   me.verts.append(v)
   v=NMesh.Vert(orix+lo+vra.val,oriy+vra.val,oriz+vra.val)
   me.verts.append(v)
   # 4 5
   v=NMesh.Vert(orix+lo+vra.val,oriy+vra.val,oriz+ha+vra.val)
   me.verts.append(v)
   v=NMesh.Vert(orix+lo+vra.val*random(),oriy+la+vra.val*random(),oriz+ha+vra.val*random())
   me.verts.append(v)
   # 6 7
   v=NMesh.Vert(orix+vra.val*random(),oriy+la+vra.val*random(),oriz+ha+vra.val*random())
   me.verts.append(v)
   v=NMesh.Vert(orix+vra.val*random(),oriy+vra.val*random(),oriz+ha+vra.val*random())
   me.verts.append(v)

   f=NMesh.Face()
   f.v.append(me.verts[0])
   f.v.append(me.verts[1])
   f.v.append(me.verts[2])
   f.v.append(me.verts[3])
   f2=NMesh.Face()
   f2.v.append(me.verts[2])
   f2.v.append(me.verts[3])
   f2.v.append(me.verts[4])
   f2.v.append(me.verts[5])
   f3=NMesh.Face()
   f3.v.append(me.verts[4])
   f3.v.append(me.verts[5])
   f3.v.append(me.verts[6])
   f3.v.append(me.verts[7])
   f4=NMesh.Face()
   f4.v.append(me.verts[0])
   f4.v.append(me.verts[7])
   f4.v.append(me.verts[4])
   f4.v.append(me.verts[3])
   f5=NMesh.Face()
   f5.v.append(me.verts[0])
   f5.v.append(me.verts[7])
   f5.v.append(me.verts[6])
   f5.v.append(me.verts[1])
   f6=NMesh.Face()
   f6.v.append(me.verts[1])
   f6.v.append(me.verts[6])
   f6.v.append(me.verts[5])
   f6.v.append(me.verts[2])
   me.faces.append(f)
   me.faces.append(f2)
   me.faces.append(f3)
   me.faces.append(f4)
   me.faces.append(f5)
   me.faces.append(f6)

   ioa = 1000*iaa + 100*ia +i
   aaa = "box%s" % ioa


   NMesh.PutRaw(me,aaa,1)

################################# #

General User Interface

################################## #
def gui():
####### #
global pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, vra, fun, funn, fnn, fuu

BGL.glClearColor(0.55,0.6,0.65, 1)
BGL.glColor3f(0.0,0.0,0.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glRasterPos2d(10, 420)
Blender.Draw.Text("------------------------------------")
BGL.glRasterPos2d(10, 342.50)
Blender.Draw.Text("------------------------------------")
BGL.glRasterPos2d(10, 253.75)
Blender.Draw.Text("------------------------------------")
BGL.glRasterPos2d(10, 123.75)
Blender.Draw.Text("------------------------------------")
BGL.glRasterPos2d(10, 73.75)
Blender.Draw.Text("------------------------------------")
BGL.glRasterPos2d(10, 2.50)
Blender.Draw.Text("------------------------------------")
BGL.glColor3f(0.9,0.0,0.0)
BGL.glRasterPos2d(255, 37.50)
Blender.Draw.Text("------")

pilex = Blender.Draw.Number("X box(es) = ",3,10,360,100,50,pilex.val,1,10,“Number of boxes in X axe”)
piley = Blender.Draw.Number("Y box(es) = ",3,120,360,100,50,piley.val,1,10,“Number of boxes in Y axe”)
pilez = Blender.Draw.Number("Z box(es) = ",3,230,360,100,50,pilez.val,1,25,“Number of boxes in Z axe”)

sizex = Blender.Draw.Number(“x size =”,3,10,310,100,25,sizex.val,0.0,50.0,“x size of boxes”)
sizey = Blender.Draw.Number(“y size =”,3,120,310,100,25,sizey.val,0.0,50.0,“y size of boxes”)
sizez = Blender.Draw.Number(“z size =”,3,230,310,100,25,sizez.val,0.0,50.0,“z size of boxes”)

sizexra = Blender.Draw.Number(“Rndsize x =”,3,10,270,100,25,sizexra.val,0.0,50.0,“random x size of boxes”)
sizeyra = Blender.Draw.Number(“Rndsize y =”,3,120,270,100,25,sizeyra.val,0.0,50.0,“random y size of boxes”)
sizezra = Blender.Draw.Number(“Rndsize z =”,3,230,270,100,25,sizezra.val,0.0,50.0,“random z size of boxes”)

posx = Blender.Draw.Number(“x pos. =”,3,10,220,100,25,posx.val,-50.0,50.0,“position of boxes on X axe”)
posy = Blender.Draw.Number(“y pos. =”,3,120,220,100,25,posy.val,-50.0,50.0,“position of boxes on Y axe”)
posz = Blender.Draw.Number(“z pos. =”,3,230,220,100,25,posz.val,-50.0,50.0,“position of boxes on Z axe”)

posxra = Blender.Draw.Number(“Rndpos x =”,3,10,180,100,25,posxra.val,-50.0,50.0,“random position of boxes on X axe”)
posyra = Blender.Draw.Number(“Rndpos y =”,3,120,180,100,25,posyra.val,-50.0,50.0,“random position of boxes on Y axe”)
poszra = Blender.Draw.Number(“Rndpos z =”,3,230,180,100,25,poszra.val,-50.0,50.0,“random position of boxes on Z axe”)

slopex = Blender.Draw.Number(“slope x =”,3,10,140,100,25,slopex.val,-10.0,10.0,“slope on X”)
slopey = Blender.Draw.Number(“slope y =”,3,120,140,100,25,slopey.val,-10.0,10.0,“slope on Y”)
slopez = Blender.Draw.Number(“slopes =”,3,230,140,100,25,slopez.val,-10.0,10.0,“slope’s”)

fun = Blender.Draw.Number(“noname1=”,3,120,105,100,15,fun.val,-10.0,10.0,“i dont have a name for this FUNction”)
funn = Blender.Draw.Number(“noname2=”,3,230,105,100,15,funn.val,-10.0,10.0,“i dont have a name for this FUNction”)
fnn = Blender.Draw.Number(“noname3=”,3,120,85,100,15,fnn.val,-10.0,10.0,“i dont have a name for this FUNction”)
fuu = Blender.Draw.Number(“noname4=”,3,230,85,100,15,fuu.val,-10.0,10.0,“i dont have a name for this FUNction”)

vra = Blender.Draw.Number(“Chaos =”,3,10,90,100,25,vra.val,0.0,10.0,“Randomise vertices”)

Blender.Draw.Button(“preset1”, 11, 115,55,50,15, “Piki piles”)
Blender.Draw.Button(“preset2”, 12, 115,35,50,15, “Random city”)
Blender.Draw.Button(“preset3”, 13, 115,15,50,15, “Flat”)
Blender.Draw.Button(“preset4”, 14, 175,55,50,15, “Block’s”)
Blender.Draw.Button(“preset5”, 15, 175,35,50,15, “Stair”)
Blender.Draw.Button(“preset6”, 16, 175,15,50,15, “Wall”)

Blender.Draw.Button(“Generate”,2,22.50,17.50,75,50,“Generate the boxes”)
Blender.Draw.Button(“Reset”, 17, 255,50,50,15, “Reset buttons”)
Blender.Draw.Button(“Exit”, 1, 255,20,50,15, “Exit script”)

def event(evt, val):
if (evt== Blender.Draw.QKEY and not val):
gui.Exit()

def bevent(evt):
if (evt== 2):
create(pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, vra, fun, funn, fnn, fuu)
Blender.Redraw()

elif (evt== 3):
create(pilez, piley, pilex, sizez, sizey, sizex, sizezra, sizeyra, sizexra, posx, posy, posz, posxra, posyra, poszra, slopey, slopex, slopez, vra, fun, funn, fnn, fuu)
Blender.Redraw()

elif (evt== 11): preset1()

elif (evt== 12): preset2()

elif (evt== 13): preset3()

elif (evt== 14): preset4()

elif (evt== 15): preset5()

elif (evt== 16): preset6()

elif (evt== 17): lancer()

if evt == 1:
gui.Exit()
Blender.Redraw()

lancer()
Blender.Draw.Register(gui, event, bevent)

I have never done any scripting bevore,
so , no questions please.