I have managed to modifie the script to include a button style and a slider style interface to creating a house,
this is sothat you dont have to mod a randomly generated one. the random one is still in this script.
#!BPY
"""
Name: 'Home Designer'
Blender: 237
Group: 'Mesh'
Tip: 'Creates VERY simple house-like meshes'
"""
# basic source - url - https://blenderartists.org/forum/viewtopic.php?t=45593
import Blender
from Blender import *
from Blender.Draw import *
# Define the action buttons here
# Must start with a E_
E_DEBUG = 1 # 1 for debug to be on.0 for off.
E_EXIT = 10 # also set to QKEY
E_RANDOM = 1
E_CUSTOM = 2
E_CUSTOM_SLIDER = 3
E_CUSTOM_NAME = 'Create a custom building'
E_CUSTOM_NAME2 = 'Create a custom building [sliders]'
E_RANDOM_NAME = 'Click to generate a Random sized house.'
dist = Create(0.2)
dist1 = Create(1.2)
dist2 = Create(2.2)
dist3 = Create(3.2)
negfive = Create(-5.0)
zero = Create(0.0)
one = Create(1.0)
two = Create(2.0)
three = Create(3.0)
four = Create(4.0)
five = Create(5.0)
six = Create(6.0)
print " Home Designer 0.3"
if (E_DEBUG == 1):
print ">> Debug Mode ON" # [ you can switch this by the debug button in your GUI ]"
#size=Buffer(GL_FLOAT, 4)
# glGetFloatv(GL_SCISSOR_BOX, size)
#size= size.list
# Create the action buttons here
def buton ():
global xC, yC, hpC, hsC, wC, lC, xC2, yC2, hpC2, hsC2, wC2, lC2, Toggle
# Button functions.
# Button(label, event, x, y, width, height, [tooltip])
# Number(label, event, x, y, width, height, initial, min, max, [tooltip])
# Scrollbar(event, x, y, width, height, initial, min, max, [update, tooltip])
# Slider(label, event, x, y, width, height, initial, min, max, [update, tooltip])
# String(label, event, x, y, width, height, initial, length, [tooltip])
# Toggle(label, event, x, y, width, height, default, [tooltip])
Button ('Custom House', E_CUSTOM, 50, 410, 160, 25, E_CUSTOM_NAME)
Button ('Custom House 2', E_CUSTOM_SLIDER, 50, 160, 160, 25, E_CUSTOM_NAME2)
# House Values for your Custom House.
xC = Number('X', 6, 50, 390, 100, 15, 1, -5, 5, 'X Value')
yC = Number('Y', 6, 50, 375, 100, 15, 1, -5, 5, 'Y Value')
hpC = Number('HP', 6, 50, 360, 100, 15, 1, 0, 5, 'HP Value')
hsC = Number('HS', 6, 50, 345, 100, 15, 1, 1, 2, 'HS Value')
wC = Number('W', 6, 50, 330, 100, 15, 2, 2, 4, 'W Value')
lC = Number('L', 6, 50, 315, 100, 15, 2, 2, 6, 'L Value')
#slider = Slider("slider",12,20,170,200,18,slider.val,-10,10,0,"X Value")
xC2 = Slider("xC ",7,50,290,150,20,dist.val,negfive.val,five.val,0,"Size of value X")
yC2 = Slider("yC ",7,50,270,150,20,dist.val,negfive.val,five.val,0,"Size of value Y")
hpC2 = Slider("hpC ",7,50,250,150,20,dist1.val,zero.val,five.val,0,"Size of value HP")
hsC2 = Slider("hsC ",7,50,230,150,20,dist1.val,one.val,two.val,0,"Size of value HS")
wC2 = Slider("wC ",7,50,210,150,20,dist3.val,two.val,four.val,0,"Size of value W")
lC2 = Slider("lC ",7,50,190,150,20,dist3.val,two.val,four.val,0,"Size of value L")
#lacunarityBout=Slider("lacunarity", E_NOISELAC ,40 ,size[3]-n0-158 ,175,20, lacunarityBout.val, -4.0,+4.0,0,)
#lacunarityBout=Slider("lacunarity", E_NOISELAC ,40 ,size[3]-n0-158 ,175,20, lacunarityBout.val, -4.0,+4.0,0,)
#octavesBout=Slider("octave", E_NOISEOCT ,40 ,size[3]-n0-178 ,175,20, octavesBout.val, -10.0,+10.0,0,)
#offsetBout=Slider("offset", E_NOISEOFF ,40 ,size[3]-n0-198 ,175,20, offsetBout.val, -5.0,+5.0,0,)
#Scrollbar('Height', 100, 100, 50, 30, 1, 0, 10, 'Select Height of your House')
#Slider('Height', 1, 150, size[3]-n0-198 , 200, 100, 5, 1, 10, 'Select house value')
#Slider("offset", 1, 40 , size[3]-n0-198 , 175, 20 , offsetBout.val, -5.0,+5.0,0,)
#String('String', 5, 50, 150, 200, 20, 10, 250, 'String tip')
Toggle('Debug', 4, 50, 120, 100, 20, 1, 'toggle tip')
Button ('Generate', E_RANDOM, 50, 50, 100, 25, E_RANDOM_NAME)
#Number('Number', 6, 50, 180, 200, 20, 1, 0, 10, 'Number tip')
#Scrollbar('Scrollbar', 50, 240, 200, 20, 1, 0, 10, 'Update','Tip')
def exit (evt, val):
if (evt == QKEY and not val):
Exit()
def event (ev):
global xC, yC, hpC, hsC, wC, lC, xC2, yC2, hpC2, hsC2, wC2, lC2, Toggle
if ev == 7:
# event called when a user selects the number values.
if (E_DEBUG == 1):
print ">> Slider selected"
print "x = ",xC2
print "y = ",yC2
print "hp = ",hpC2
print "hs = ",hsC2
print "w = ",wC2
print "l = ",lC2
if ev == 6:
# event called when a user selects the number values.
if (E_DEBUG == 1):
print ">> Button selected"
print "x = ",xC
print "y = ",yC
print "hp = ",hpC
print "hs = ",hsC
print "w = ",wC
print "l = ",lC
if ev == 3:
# Draw a custom house selected by the user.
xC2 = eval(str(xC2))
yC2 = eval(str(yC2))
hpC2 = eval(str(hpC2))
hsC2 = eval(str(hsC2))
wC2 = eval(str(wC2))
lC2 = eval(str(lC2))
if (E_DEBUG == 1):
print ">> Create a Custom house with the following cordinates.[Slider style]"
print "x = ",xC2
print "y = ",yC2
print "hp = ",hpC2
print "hs = ",hsC2
print "w = ",wC2
print "l = ",lC2
#x = eval(xC2)
#w = eval(wC2)
#x = Float(xC2)
#w = Float(wC2)
#x = Mathutils.Rand (-4,4)
#w = Mathutils.Rand (2,4)
semiC2 = xC2 + (wC2/2)
if (E_DEBUG == 1):
print "semi = ",semiC2
CreateHouse(xC2, yC2, hpC2, hsC2, wC2, lC2, semiC2)
if ev == 2:
# Draw a custom house selected by the user.
if (E_DEBUG == 1):
print ">> Create a Custom house with the following cordinates.[button style]"
print "x = ",xC
print "y = ",yC
print "hp = ",hpC
print "hs = ",hsC
print "w = ",wC
print "l = ",lC
# could add a cheeky hack here to try get the floats correct
# select a random from the point the user chose to 1 int above it.
# TODO : figure out adding numbers to a int or make the float correctly
# if i can do this the form section will work correctly
# built-in functions int(), long(), and float() convert inputs
# int(float('0.0123456789'))
#xC2 = int(xC)+1
#yC2 = int(yC)+1
#hpC2 = int(hpC)+1
#hsC2 = int(hsC)+1
#wC2 = int(wC)+1
#lC2 = int(lC)+1
#x = Mathutils.Rand (xC,xC2)
#y = Mathutils.Rand (yC,yC2)
#hp = Mathutils.Rand (hpC,hpC2)
#hs = Mathutils.Rand (hsC,hsC2)
#w = Mathutils.Rand (wC,wC2)
#l = Mathutils.Rand (lC,lC2)
#semi = xC2 + (wC2/2)
x = eval(str(xC))
y = eval(str(yC))
hp = eval(str(hpC))
hs = eval(str(hsC))
w = eval(str(wC))
l = eval(str(lC))
semi = x + (w/2)
if (E_DEBUG == 1):
print " >> new values"
print "x = ",x
print "y = ",y
print "hp = ",hp
print "hs = ",hs
print "w = ",w
print "l = ",l
print "semi = ",semi
#x = int(xC)
#y = int(yC)
#hp = int(hpC)
#hs = int(hsC)
#w = int(wC)
#l = int(lC)
#semi = xC + (wC/2)
#CreateHouse(xC, yC, hpC, hsC, wC, lC, 3.99604322016)
CreateHouse(x, y, hp, hs, w, l, semi)
#CreateHouse(-1.67735946365, -2.92192997411, 2.13155810256, 1.29031124152, 2.51938086469, 5.95548190922, 3.99604322016)
return
elif ev == 1:
# user does not know what he wants so draw a random house.
# Draw a random size house for the user.
# Returns a random number eg: 2.03430345967
x = Mathutils.Rand (-5,5)
y = Mathutils.Rand (-5,5)
hp = Mathutils.Rand (0,5)
hs = Mathutils.Rand (1,2)
w = Mathutils.Rand (2,4)
l = Mathutils.Rand (2,6)
semi = x + (w/2)
if (E_DEBUG == 1):
print ">> Random House Generated."
print "x = ",x
print "y = ",y
print "hp = ",hp
print "hs = ",hs
print "w = ",w
print "l = ",l
print "semi = ",semi
CreateHouse(x, y, hp, hs, w, l, semi)
return
Register (buton, exit, event)
# Main Function to use when drawing a simple block house.
def CreateHouse(x, y, hp, hs, w, l, semi):
if (E_DEBUG == 1):
print ">> Inside CreateHouse"
print "x = ",x
print "y = ",y
print "hp = ",hp
print "hs = ",hs
print "w = ",w
print "l = ",l
print "semi = ",semi
mesh = NMesh.New()
# Method: NMesh.Vert([x, y, z])
# Returns a new NMVert object, created from the given x,y,and z coordinates. If any of the coordinates are not passed they default to 0.0.
a = NMesh.Vert (x,y,0)
b = NMesh.Vert ((x+w),y,0)
c = NMesh.Vert ((x+w),(y+l),0)
d = NMesh.Vert (x,(y+l),0)
e = NMesh.Vert (x,y,hp)
f = NMesh.Vert ((x+w),y,hp)
g = NMesh.Vert ((x+w),(y+l),hp)
h = NMesh.Vert (x,(y+l),hp)
i = NMesh.Vert (semi,y,(hp+hs))
j = NMesh.Vert (semi,(y+l),(hp+hs))
mesh.verts.append (a)
mesh.verts.append (b)
mesh.verts.append (c)
mesh.verts.append (d)
mesh.verts.append (e)
mesh.verts.append (f)
mesh.verts.append (g)
mesh.verts.append (h)
mesh.verts.append (i)
mesh.verts.append (j)
# Method: NMesh.Face()
# Face() Return a new NMCol object created from the given r,g,b, and a color components. If any of the components are not passed they default to 255.
abcd = NMesh.Face ([a,b,c,d])
abfe = NMesh.Face ([a,b,f,e])
bcgf = NMesh.Face ([b,c,g,f])
cdhg = NMesh.Face ([c,d,h,g])
daeh = NMesh.Face ([d,a,e,h])
efi = NMesh.Face ([e,f,i])
ghj = NMesh.Face ([g,h,j])
fgji = NMesh.Face ([f,g,j,i])
heij = NMesh.Face ([h,e,i,j])
# these dimensions are taken from the frount camera view.
# These are each pannel that will be placed and put together.
mesh.faces.append (abcd) # Floor
mesh.faces.append (abfe) # Frount Wall
mesh.faces.append (bcgf) # Right Wall
mesh.faces.append (cdhg) # Back Wall
mesh.faces.append (daeh) # Left Wall
mesh.faces.append (efi) # Frount Roof Triangle
mesh.faces.append (ghj) # Back Roof Triangle
mesh.faces.append (fgji) # Right Roof
mesh.faces.append (heij) # Left Roof
# New Mesh Object will be created from the values set in our mesh object.
obj = Object.New ("Mesh", "AidansHome")
obj.link (mesh)
Scene.GetCurrent().link(obj)
# Method: Blender.Redraw()
# This function forces an immediate redraw of all 3D windows in the current screen. It can be used to force display of updated information (for example when an IPO curve for an Object has been changed).
Blender.Redraw()
Register (buton, exit, event)
if you can find something that can help me get this app a bit further please post it here.
there is one thing about the app thats bugging me, after each house you make from the slider or button the slider values reset back to the defaults.
how can i fix this sothat it does not???