here’s the script :
http://pikilipita.free.fr/blender/piki-stalac.py
It’s a script which randomly creates several piles of boxes.
It’s not very usefull, but i made it as an exercise…
here’s the result :
And here’s a Yafray render :
here’s the script :
http://pikilipita.free.fr/blender/piki-stalac.py
It’s a script which randomly creates several piles of boxes.
It’s not very usefull, but i made it as an exercise…
here’s the result :
And here’s a Yafray render :
I don’t think you should characterize it as ‘not very useful’. Fiddling with a few of the parameters would enable it to generate cities, molecules, pseudo-metaballs, treetrunks… and in conjunction with the build effect…
Don’t get boxed in by the boxes!
%<
This could be the beginning of a nice greeble plugin!
Fligh is right, this script could very well be the beginning of a city script, like the one here. http://members.tripod.com/~DCieslak/util.html
Exactly !
My initial goal was to make a city gerenator.
But for the moment, i’ll try simpler things…
I’ve updated my script, it now has a Gui, and you can choose
a few values in the generator.
BUT , each time you hit the “generate” button, the value of
each button return to its start value.
AND i don’t want this toi happen…
How to make the buttons not to reset ?
the entire code of the script :
# My first Blender plug-in
# By me : pikilipita_at_pikilipita.com
# http://www.pikilipita.com
#It's a random cubes piles generator
#Version 1 : 5 july 2oo3
#Just press Alt + P to create the piles
import Blender
from Blender import NMesh, BGL
from random import randint, random
oriz = 0
ha = 0
orixx = 0
oriyy = 0
def action():
for iaa in range (0,piley.val,1):
oriyy = 8*iaa
for ia in range (0,pilex.val,1):
orixx= 8*ia
oriz=0
ha=0
for i in range (1,pilez.val+1,1):
oriz= oriz+ha
lo = 1.0+1*random()
la = 1.0+1*random()
ha = 1.0+1*random()
orix = orixx + random()
oriy = oriyy + 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,oriy,oriz)
me.verts.append(v)
v=NMesh.Vert(orix,oriy+la,oriz)
me.verts.append(v)
v=NMesh.Vert(orix+lo,oriy+la,oriz)
me.verts.append(v)
v=NMesh.Vert(orix+lo,oriy,oriz)
me.verts.append(v)
# 4 5
v=NMesh.Vert(orix+lo,oriy,oriz+ha)
me.verts.append(v)
v=NMesh.Vert(orix+lo,oriy+la,oriz+ha)
me.verts.append(v)
# 6 7
v=NMesh.Vert(orix,oriy+la,oriz+ha)
me.verts.append(v)
v=NMesh.Vert(orix,oriy,oriz+ha)
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 = "plan %s" % ioa
NMesh.PutRaw(me,aaa,1)
def gui():
#
global pilex, piley, pilez
BGL.glClearColor(1,1,1, 1)
BGL.glColor3f(1.0,0.0,0.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glRasterPos2d(10, 230)
Blender.Draw.Text("a script by")
BGL.glRasterPos2d(10, 210)
Blender.Draw.Text("PIKILIPITA STUDIO - http://pikilipita.com")
BGL.glRasterPos2d(10, 160)
Blender.Draw.Text("Any new boxes generation will erase the last one !")
BGL.glRasterPos2d(10, 140)
Blender.Draw.Text("High values will increase a lot the generation time needed !")
pilez = Blender.Draw.Number("boxe(s) = ",3,10,80,100,25,1,1,25,"Number of boxes in each pile")
pilex = Blender.Draw.Number("x pile(s) = ",3,230,80,100,25,1,1,5,"Number of piles in X axe")
piley = Blender.Draw.Number("y pile(s) = ",3,120,80,100,25,1,1,5,"Number of piles in Y axe")
Blender.Draw.Button("Generate",2,10,10,100,25,"Generate the boxes")
Blender.Draw.Button("Exit", 1, 120,10,100,25, "Exit script")
def event(evt, val):
if (evt== Blender.Draw.QKEY and not val):
Draw.Exit()
def bevent(evt):
if (evt== 2):
action()
Blender.Redraw()
if evt == 1:
draw.Exit()
Blender.Draw.Register(gui, event, bevent)
Thanks for any help
try this:
def gui():
#
global pilex, piley, pilez
BGL.glClearColor(1,1,1, 1)
BGL.glColor3f(1.0,0.0,0.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glRasterPos2d(10, 230)
Blender.Draw.Text("a script by")
BGL.glRasterPos2d(10, 210)
Blender.Draw.Text("PIKILIPITA STUDIO - http://pikilipita.com")
BGL.glRasterPos2d(10, 160)
Blender.Draw.Text("Any new boxes generation will erase the last one !")
BGL.glRasterPos2d(10, 140)
Blender.Draw.Text("High values will increase a lot the generation time needed !")
pilez = Blender.Draw.Number("boxe(s) = ",3,10,80,100,25,pilez.val,1,25,"Number of boxes in each pile")
pilex = Blender.Draw.Number("x pile(s) = ",3,230,80,100,25,pilex.val,1,5,"Number of piles in X axe")
piley = Blender.Draw.Number("y pile(s) = ",3,120,80,100,25,piley.val,1,5,"Number of piles in Y axe")
Blender.Draw.Button("Generate",2,10,10,100,25,"Generate the boxes")
Blender.Draw.Button("Exit", 1, 120,10,100,25, "Exit script")
The trick is to replace the Default values in the buttons by the value of the button (variable.val).
Martin
Oh yes, i understand !
Thanks
Oh no,
it didn’t worked
File “piki-stalac.py”, line 113, in gui
ttributeError: ‘int’ object has no attribute ‘val’
or
File “piki-stalac.py”, line 113, in gui
ttributeError: ‘float’ object has no attribute ‘val’
try initializing them at the start of the script.
pilex = Blender.Draw.Create(1)
piley = Blender.Draw.Create(1)
pilez = Blender.Draw.Create(1)
You need to use the Blender.Draw.Create function when you want to use a variable to store a button’s value.
Martin
Thanks a lot Theeth, it worked !
a few last questions :
what is the default value of a variable when you use it for the first time ?
Zero ?
How, using script, can i delete one of my boxes ?
for example the one called :
ME:box1 OB:Mesh.001
And by the way,
i guess , ME is for mesh and OB for objet
but what is the difference between a mesh and an objet ?
is this difference only used in realtime engine ?
A variable is not initialised until you create it. Then, when you create it, it has the value you give it, so there is no initial value as is.
I don’t recal how to do that, but there must be a way.
The Object contains the data about the position, rotation and sizing of the object. The Mesh contains the data that is inside the object. If it is a mesh, that means that the Object data is linked with a Mesh data. You can also link Lamp data with Object data, Camera data with Object data, …
I hope that’s a bit clear.
Martin