Homemaker

Good God, I’d forgotten about this thread o__O All I can say is, damn, cryptic, that’s some l33t coding :smiley:

Anyway, as it hapens, this morning I got a bit of time for myself so I thought I’d tinker with the script a bit more. The idea I tried to implement was the generation of several houses at once. I managed to do it, but I’m not quite satisfied – I want the user to be able to control the ranges of the size variations. I’m also trying to ge t a decent way of correctly rotating the houses a bit, so they don’t look like they’re on a 2-dimentional array (they are, but that is so not the point :stuck_out_tongue: )

It would be nice to get roofs that was a bit bigger than the base of the house (Hope you understand what I meen) I tried to uv-map you houses and that was the only thing that looked unnatural with the houses.

Another thing is to get another style of houses, If you are building a city, you would like some scrapes too, and maybe a cathedral? That would be nice!

Simple script, but very cool! :wink:

You mean so the profile’ll be something like

…/.
…/…
…/
…|…|
…|__|

(ph3ar my ASCII skillz0r) I’ll look into it :slight_smile:

Thats pritty much what i thought off :smiley:

And maybe some of those:


|[] [] [] |
|[] [] [] |
|[] [] [] |
|[] [] [] |
|[] [] [] |
|[] [] [] |

Or maybe some like this:

/
/
| |
| |________
| _ _ _ _ _ |
|}{U U U U U|

:wink:

thanks for the replys

this is a small project that im wanting to work on , i want to try see if we can add some features to add a more realistic enviroment for each house. what about a house that has more than one room.

like a 3 beadroom place , i would think the best way is to make 3 seperate house and join them together.

i dont know blender well at all so i need your help on this .

Kothe: Why do you hate me? :-? Heh, I’ll look into that… Next version :slight_smile:

Cryptic: Your idea of adding details is great, but I think it works for single meshes. Not that it can’t be made to work for several meshes, but it might eat up a lot of system resources. My inital idea was to have a way of quickly making whole neighbourhoods of houses, a sort of background filler thing… However, if you want to continue developing your script, I can only encourage you :slight_smile:

And here’s the last version of my script; it now supports the creation of several houses at once (max 100), (randomly) rotating the houses, some size variation (not enough, I’ll admit) and (randomly) choosing whether a house is created or not.


#!BPY

"""
Name: 'Homemaker v0.4.3'
Blender: 237
Group: 'Mesh'
Tip: 'Creates arrays of simple house-like meshes'
"""

#	import the relevant modules
import Blender
from Blender import *
from Blender.Draw import *

#	declare the globals
sld = Create (0)
lung = Create (0)

#	create the GUI
def buton ():
	global sld
	global tgl
	global rtt

	Button ('Generate', 1, 50, 50, 200, 25)
	sld = Slider ('Grid size: ', 2, 50, 130, 200, 25, sld.val, 1.0, 10.0)
	tgl = Toggle ('Remove some objects?', 3, 50, 105, 200, 25, 0)
	rtt = Toggle ('Rotate objects?', 4, 50, 80, 200, 25, 0)

#	exit on 'Q'
def exit (evt, val):
	if (evt == QKEY and not val):
		Exit()

#	on to the good stuff...
def make (lim, dim, rem, rot):

	#	the following trick, which I've (ab)used
	#	quite a lot, removes all but the first decimal
	dim = float (int(dim * 10)) / 10

	#	initialize the coordinates
	lun = 0
	lat = 0
	lun = float(lun)
	lat = float(lat)

	#	start defining the grid
	for gridy in range (lim):

		if (gridy != 0):
			lat = (dim + lat) + 1

		for gridx in range (lim):
			#	choose whether a mesh
			#	will be created or not
			if rem:
				rmv = int(Mathutils.Rand(0,20))
			else:
				rmv = 1

			if (rmv <= 13):

				#	define a new mesh
				mesh = NMesh.New()

				if (gridx != 0):
					lun = (dim + lun) + 1

				#	the random deviations
				rdm = float(int(Mathutils.Rand (3,7)) * 10) / 100
				rh = rdm
				bln = float(int(Mathutils.Rand(0,1)) * 10) / 10
				if (bln < 1):
					rdm = rdm * (-1)
				hi = float(int(Mathutils.Rand (4,10)) * 10) / 100
				hi = dim * hi

				#	start positioning the verts
				a = NMesh.Vert (rdm,rdm,0)
				b = NMesh.Vert ((dim + rdm),rdm,0)
				c = NMesh.Vert ((dim + rdm),(dim + rdm),0)
				d = NMesh.Vert (rdm,(dim + rdm),0)
				e = NMesh.Vert (rdm,rdm,(dim + rh))
				f = NMesh.Vert ((dim + rdm),rdm,(dim + rh))
				g = NMesh.Vert ((dim + rdm),(dim + rdm),(dim + rh))
				h = NMesh.Vert (rdm,(dim + rdm),(dim + rh))
				i = NMesh.Vert ((rdm + (dim / 2)), rdm, (dim + rh + hi))
				j = NMesh.Vert ((rdm + (dim / 2)), (dim + rdm), (dim + rh + hi))

				#	and append them to the mesh
				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)

				#	then define the faces
				abcd = NMesh.Face ([d,c,b,a])	#	base
				abfe = NMesh.Face ([a,b,f,e])	#	front
				bcgf = NMesh.Face ([b,c,g,f])	#	right
				cdhg = NMesh.Face ([c,d,h,g])	#	back
				daeh = NMesh.Face ([d,a,e,h])	#	left
				efi = NMesh.Face ([e,f,i])		#	front roof triangle
				ghj = NMesh.Face ([g,h,j])		#	back roof triangle
				fgji = NMesh.Face ([f,g,j,i])	#	right roof
				heij = NMesh.Face ([h,e,i,j])	#	left roof

				#	and append them to the mesh
				mesh.faces.append (abcd)
				mesh.faces.append (abfe)
				mesh.faces.append (bcgf)
				mesh.faces.append (cdhg)
				mesh.faces.append (daeh)
				mesh.faces.append (efi)
				mesh.faces.append (ghj)
				mesh.faces.append (fgji)
				mesh.faces.append (heij)

				#	create the new mesh
				obj = Object.New ("Mesh", "Casa")
				obj.link (mesh)
				Scene.GetCurrent().link(obj)

				#	position the new mesh on the grid
				obj.setLocation (lun,lat,0)

				#	rotate the mesh
				if (rot):
					[rx, ry, rz] = obj.getEuler()
					rot = float(int(Mathutils.Rand(0,9) * 10)) / 10
					rz += rot
					obj.setEuler(rx,ry,rz)

				#	create the mesh
				Blender.Redraw()

		#	reset the x values of the grid
		#	comment this for a ladder-like effect
		lun = 0

#	call the make function
def magick (evt):
	if evt == 1:
		make (sld.val, 1, tgl.val, rtt.val)

#	activate the script
Register (buton, exit, magick)

wow rocky

i like the generation of the houses , its looking good.
do you mind if i add all the features we got now into one

i think we should also try get it sothat making it possible to walk through our small town in a game type mode would be nice , i dont know if there is a script out there that could help with that already ,

ive been thinking about making some bigger buildings too.

will see how it goes once its all together.

Hey, be my guest :slight_smile:

I’m currently trying to create “streets” – empty rows and columns – and a way to add simple UV maps. But first, I need coffee :confused:

Okay, here’s what the script outputs so far (no material, 2 lights, edge rendering enabled):

http://img.photobucket.com/albums/v234/professor_destiny/4noremrot.jpg
Grid: 4 x 4
Remove: No
Rotate: Yes

http://img.photobucket.com/albums/v234/professor_destiny/6remnorot.jpg
Grid: 6 x 6
Remove: Yes
Rotate: No

http://img.photobucket.com/albums/v234/professor_destiny/8remrot.jpg
Grid: 8 x 8
Remove: Yes
Rotate: Yes

Looks good (And I don’t hate you!, I just don’t like you :P)
I would like some other house styles still though. This looks to regular!

Okay, new version :smiley: Some buildings can now be set to be taller than others; the height difference can also be set.

The settings:
http://img.photobucket.com/albums/v234/professor_destiny/settings.jpg

The result: (slightly photoshopped for emotional impact)
http://img.photobucket.com/albums/v234/professor_destiny/result.jpg

The code:

#!BPY

"""
Name: 'Homemaker v0.4.4'
Blender: 237
Group: 'Mesh'
Tip: 'Creates arrays of simple house-like meshes'
"""

#	import the relevant modules
import Blender
from Blender import *
from Blender.Draw import *

#	declare the globals
sld = lung = fls = fln = Create (0)

#	create the GUI
def buton ():
	global sld
	global tgl
	global rtt
	global fls
	global fln

	Button ('Generate', 1, 50, 50, 200, 25)
	sld = Slider ('Grid size: ', 2, 50, 190, 200, 25, sld.val, 1.0, 10.0)
	tgl = Toggle ('Remove some objects?', 3, 50, 105, 200, 25, 0)
	rtt = Toggle ('Rotate objects?', 4, 50, 80, 200, 25, 0)
	fls = Slider ('Max floors: ', 5, 50, 130, 200, 25, fls.val, 1.0, 4.0)
	fln = Slider ('Tall houses: ', 6, 50, 155, 200, 25, fln.val, 0.0, (sld.val * sld.val))

#	exit on 'Q'
def exit (evt, val):
	if (evt == QKEY and not val):
		Exit()

#	on to the good stuff...
def make (lim, dim, rem, rot, tal, etj):

	dim = float (int(dim * 10)) / 10

	lun = 0.0
	lat = 0.0

	#	start defining the grid
	for gridy in range (lim):
		if (gridy != 0):
			lat = (dim + lat) + 1.5

		for gridx in range (lim):
			#	choose whether a mesh
			#	will be created or not
			if rem:
				rmv = int(Mathutils.Rand(0,20))
			else:
				rmv = 1

			if (rmv <= 13):

				#	define a new mesh
				mesh = NMesh.New()

				if (gridx != 0):
					lun = (dim + lun) + 1

				#	the random deviations
				rdm = float(int(Mathutils.Rand (3,7)) * 10) / 100
				rh = rdm
				bln = float(int(Mathutils.Rand(0,1)) * 10) / 10
				if (bln < 1):
					rdm = rdm * (-1)
				hi = float(int(Mathutils.Rand (4,10)) * 10) / 100
				hi = dim * hi

				#	floors:
				if (tal):
					randhs = int(Mathutils.Rand (0,10))
					if (randhs <= 8):
						#	will this house have many floors?
						alt = float(int (Mathutils.Rand (1,(etj + 1)))) / 2
						tal -= 1
					else:
						alt = 0

				else:
					alt = 0							

				#	start positioning the verts
				a = NMesh.Vert (rdm,rdm,0)
				b = NMesh.Vert ((dim + rdm),rdm,0)
				c = NMesh.Vert ((dim + rdm),((dim * 1.5) + rdm),0)
				d = NMesh.Vert (rdm,((dim * 1.5) + rdm),0)
				e = NMesh.Vert (rdm,rdm,(alt + dim + rh))
				f = NMesh.Vert ((dim + rdm),rdm,(alt + dim + rh))
				g = NMesh.Vert ((dim + rdm),((dim * 1.5) + rdm),(alt + dim + rh))
				h = NMesh.Vert (rdm,((dim * 1.5) + rdm),(alt + dim + rh))
				i = NMesh.Vert ((rdm - 0.1),(rdm - 0.1),(alt + dim + rh))
				j = NMesh.Vert ((dim + rdm + 0.1),(rdm - 0.1),(alt + dim + rh))
				k = NMesh.Vert ((dim + rdm + 0.1),((dim * 1.5) + rdm + 0.1),(alt + dim + rh))
				l = NMesh.Vert ((rdm - 0.1),((dim * 1.5) + rdm + 0.1),(alt + dim + rh))
				m = NMesh.Vert ((rdm + (dim / 2)), (rdm + 0.15), (alt + dim + rh + hi))
				n = NMesh.Vert ((rdm + (dim / 2)), ((dim * 1.5) + rdm - 0.15), (alt + dim + rh + hi))

				#	and append them to the mesh
				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)
				mesh.verts.append (k)
				mesh.verts.append (l)
				mesh.verts.append (m)
				mesh.verts.append (n)

				#	then define the faces
				abcd = NMesh.Face ([d,c,b,a])
				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])
				efji = NMesh.Face ([e,f,j,i])
				fgkj = NMesh.Face ([f,g,k,j])
				ghlk = NMesh.Face ([g,h,l,k])
				heil = NMesh.Face ([h,e,i,l])
				ijm = NMesh.Face ([i,j,m])
				kln = NMesh.Face ([k,l,n])
				jknm = NMesh.Face ([j,k,n,m])
				limn = NMesh.Face ([l,i,m,n])

				#	and append them to the mesh
				mesh.faces.append (abcd)
				mesh.faces.append (abfe)
				mesh.faces.append (bcgf)
				mesh.faces.append (cdhg)
				mesh.faces.append (daeh)
				mesh.faces.append (efji)
				mesh.faces.append (fgkj)
				mesh.faces.append (ghlk)
				mesh.faces.append (heil)
				mesh.faces.append (ijm)
				mesh.faces.append (kln)
				mesh.faces.append (jknm)
				mesh.faces.append (limn)

				#	create the new mesh
				obj = Object.New ("Mesh", "Casa")
				obj.link (mesh)
				Scene.GetCurrent().link(obj)

				#	position the new mesh on the grid
				obj.setLocation (lun,lat,0)

				#	rotate the mesh
				if (rot):
					[rx, ry, rz] = obj.getEuler()
					rotate = float(int(Mathutils.Rand(0,9) * 10)) / 10
					rz += rotate
					obj.setEuler(rx,ry,rz)

				#	create the mesh
				Blender.Redraw()

		#	reset the x values of the grid
		#	comment this for a ladder-like effect
		lun = 0

#	call the make function
def magick (evt):
	if evt == 1:
		make (sld.val, 1, tgl.val, rtt.val, fln.val, fls.val)

#	activate the script
Register (buton, exit, magick)

Oh, I’m still waiting for a decent name suggestion… %|

[edit]
Rong speling

…And a new version OMG. Cleaned up the code a wee bit, and now the houses may also have chimneys :slight_smile:

http://img.photobucket.com/albums/v234/professor_destiny/5113yy.jpg
Grid: 5 x 5
Tall houses: Maximum 11
Maximum floors: 3
Remove some houses: Yes
Rotate houses: Yes

#!BPY

"""
Name: 'Homemaker v0.4.5'
Blender: 237
Group: 'Mesh'
Tip: 'Creates arrays of simple house-like meshes'
"""

#	import the relevant modules
import Blender
from Blender import *
from Blender.Draw import *

#	declare the globals
sld = lung = fls = fln = Create (0)

#	create the GUI
def buton ():
	global sld
	global tgl
	global rtt
	global fls
	global fln

	Button ('Generate', 1, 50, 50, 200, 25)
	sld = Slider ('Grid size: ', 2, 50, 190, 200, 25, sld.val, 1.0, 10.0)
	tgl = Toggle ('Remove some objects?', 3, 50, 105, 200, 25, 0)
	rtt = Toggle ('Rotate objects?', 4, 50, 80, 200, 25, 0)
	fls = Slider ('Max floors: ', 5, 50, 130, 200, 25, fls.val, 1.0, 4.0)
	fln = Slider ('Tall houses: ', 6, 50, 155, 200, 25, fln.val, 0.0, (sld.val * sld.val))

#	exit on 'Q'
def exit (evt, val):
	if (evt == QKEY and not val):
		Exit()

#	on to the good stuff...
def make (lim, dim, rem, rot, tal, etj):

	dim = float (int(dim * 10)) / 10

	lun = 0.0
	lat = 0.0

	#	start defining the grid
	for gridy in range (lim):
		if (gridy != 0):
			lat = (dim + lat) + 1.5

		for gridx in range (lim):
			#	choose whether a mesh
			#	will be created or not
			if rem:
				rmv = int(Mathutils.Rand(0,20))
			else:
				rmv = 1

			if (rmv <= 13):

				#	define a new mesh
				mesh = NMesh.New()

				if (gridx != 0):
					lun = (dim + lun) + 1

				#	the random deviations
				rdm = float(int(Mathutils.Rand (3,7)) * 10) / 100
				rh = rdm + 0.1
				bln = float(int(Mathutils.Rand(0,1)) * 10) / 10
				if (bln < 1):
					rdm = rdm * (-1)
				hi = float(int(Mathutils.Rand (4,10)) * 10) / 100
				hi = dim * hi

				#	floors:
				if (tal):
					randhs = int(Mathutils.Rand (0,10))
					if (randhs <= 8):
						#	will this house have many floors?
						alt = float(int (Mathutils.Rand (1,(etj + 1)))) / 2
						tal -= 1
					else:
						alt = 0

				else:
					alt = 0							

				#	start positioning the verts
				wid = dim + rdm
				len = (dim * 1.5) + rdm
				hei = alt + dim + rh
				a = NMesh.Vert (rdm,rdm,0)
				b = NMesh.Vert (wid,rdm,0)
				c = NMesh.Vert (wid,len,0)
				d = NMesh.Vert (rdm,len,0)
				e = NMesh.Vert (rdm,rdm,hei)
				f = NMesh.Vert (wid,rdm,hei)
				g = NMesh.Vert (wid,len,hei)
				h = NMesh.Vert (rdm,len,hei)
				i = NMesh.Vert ((rdm - 0.1),(rdm - 0.1),hei)
				j = NMesh.Vert ((wid + 0.1),(rdm - 0.1),hei)
				k = NMesh.Vert ((wid + 0.1),(len + 0.1),hei)
				l = NMesh.Vert ((rdm - 0.1),(len + 0.1),hei)
				m = NMesh.Vert ((rdm + (dim / 2)), (rdm + 0.15), (hei + hi))
				n = NMesh.Vert ((rdm + (dim / 2)), (len - 0.15), (hei + hi))

				#	and append them to the mesh
				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)
				mesh.verts.append (k)
				mesh.verts.append (l)
				mesh.verts.append (m)
				mesh.verts.append (n)

				#	then define the faces
				abcd = NMesh.Face ([d,c,b,a])
				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])
				efji = NMesh.Face ([e,f,j,i])
				fgkj = NMesh.Face ([f,g,k,j])
				ghlk = NMesh.Face ([g,h,l,k])
				heil = NMesh.Face ([h,e,i,l])
				ijm = NMesh.Face ([i,j,m])
				kln = NMesh.Face ([k,l,n])
				jknm = NMesh.Face ([j,k,n,m])
				limn = NMesh.Face ([l,i,m,n])

				#	and append them to the mesh
				mesh.faces.append (abcd)
				mesh.faces.append (abfe)
				mesh.faces.append (bcgf)
				mesh.faces.append (cdhg)
				mesh.faces.append (daeh)
				mesh.faces.append (efji)
				mesh.faces.append (fgkj)
				mesh.faces.append (ghlk)
				mesh.faces.append (heil)
				mesh.faces.append (ijm)
				mesh.faces.append (kln)
				mesh.faces.append (jknm)
				mesh.faces.append (limn)

				#	make chimneys
				number = int (Mathutils.Rand (0,3))
				for contor in range (number):
					ch = float (int (Mathutils.Rand (rdm,(wid - 0.1) * 100))) / 100
					ich = hei + hi + (Mathutils.Rand (0,0.5))
					randis = float (int (Mathutils.Rand(0,0.1) * 100)) / 100

					cha = NMesh.Vert (ch,ch,hei)
					chb = NMesh.Vert ((ch + 0.1),ch,hei)
					chc = NMesh.Vert ((ch + 0.1),(ch + 0.1 + randis),hei)
					chd = NMesh.Vert (ch,(ch + 0.1 + randis),hei)
					che = NMesh.Vert (ch,ch,ich)
					chf = NMesh.Vert ((ch + 0.1),ch,ich)
					chg = NMesh.Vert ((ch + 0.1),(ch + 0.1 + randis),ich)
					chh = NMesh.Vert (ch,(ch + 0.1 + randis),ich)
					chi = NMesh.Vert ((ch - 0.02),(ch - 0.02),ich)
					chj = NMesh.Vert ((ch + 0.12),(ch - 0.02),ich)
					chk = NMesh.Vert ((ch + 0.12),(ch + 0.12 + randis),ich)
					chl = NMesh.Vert ((ch - 0.02),(ch + 0.12 + randis),ich)
					chm = NMesh.Vert ((ch - 0.02),(ch - 0.02),(ich + 0.03))
					chn = NMesh.Vert ((ch + 0.12),(ch - 0.02),(ich + 0.03))
					cho = NMesh.Vert ((ch + 0.12),(ch + 0.12 + randis),(ich + 0.03))
					chp = NMesh.Vert ((ch - 0.02),(ch + 0.12 + randis),(ich + 0.03))

					mesh.verts.append(cha)
					mesh.verts.append(chb)
					mesh.verts.append(chc)
					mesh.verts.append(chd)
					mesh.verts.append(che)
					mesh.verts.append(chf)
					mesh.verts.append(chg)
					mesh.verts.append(chh)
					mesh.verts.append(chi)
					mesh.verts.append(chj)
					mesh.verts.append(chk)
					mesh.verts.append(chl)
					mesh.verts.append(chm)
					mesh.verts.append(chn)
					mesh.verts.append(cho)
					mesh.verts.append(chp)

					chabcd = NMesh.Face ([chd,chc,chb,cha])
					chabfe = NMesh.Face ([cha,chb,chf,che])
					chbcgf = NMesh.Face ([chb,chc,chg,chf])
					chcdhg = NMesh.Face ([chc,chd,chh,chg])
					chdaeh = NMesh.Face ([chd,cha,che,chh])
					chefji = NMesh.Face ([che,chf,chj,chi])
					chfgkj = NMesh.Face ([chf,chg,chk,chj])
					chghlk = NMesh.Face ([chg,chh,chl,chk])
					chheil = NMesh.Face ([chh,che,chi,chl])
					chijnm = NMesh.Face ([chi,chj,chn,chm])
					chjkon = NMesh.Face ([chj,chk,cho,chn])
					chklpo = NMesh.Face ([chk,chl,chp,cho])
					chlimp = NMesh.Face ([chl,chi,chm,chp])
					chmnop = NMesh.Face ([chm,chn,cho,chp])

					mesh.faces.append (chabcd)
					mesh.faces.append (chabfe)
					mesh.faces.append (chbcgf)
					mesh.faces.append (chcdhg)
					mesh.faces.append (chdaeh)
					mesh.faces.append (chefji)
					mesh.faces.append (chfgkj)
					mesh.faces.append (chghlk)
					mesh.faces.append (chheil)
					mesh.faces.append (chijnm)
					mesh.faces.append (chjkon)
					mesh.faces.append (chklpo)
					mesh.faces.append (chlimp)
					mesh.faces.append (chmnop)

				#	create the new mesh
				obj = Object.New ("Mesh", "House")
				obj.link (mesh)
				Scene.GetCurrent().link(obj)

				#	position the new mesh on the grid
				obj.setLocation (lun,lat,0)

				#	rotate the mesh
				if (rot):
					[rx, ry, rz] = obj.getEuler()
					rotate = float(int(Mathutils.Rand(0,9) * 10)) / 10
					rz += rotate
					obj.setEuler(rx,ry,rz)

				#	create the mesh
				Blender.Redraw()

		#	reset the x values of the grid
		lun = 0

#	call the make function
def magick (evt):
	if evt == 1:
		make (sld.val, 1, tgl.val, rtt.val, fln.val, fls.val)

#	activate the script
Register (buton, exit, magick)

Hey dudes.

Well ive managed to import my changes and your changes into one script .

ive kept the basic house structure for the slider and the button , it actualy works quite well if you want to make a random building thats quite big but does not just look like a big house. i think a toggle button to switch between making a old style or new style could be cool.

any how my coding is getting better but still not the greatest you know the drill.
Here are some picutes:

http://www.galore.co.za/images/housesEx.gif

http://www.galore.co.za/images/screenEx.gif

please excuse the long amount of code…


#!BPY

"""
Name: 'Home Designer extreme'
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_ for eliance

E_DEBUG  = 1 # 1 for debug to be on.0 for off.


E_EXIT     = 911	# also set to QKEY
E_RANDOM   = 11
E_CUSTOM_BUTTON   = 10
E_CUSTOM_SLIDER   = 9
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.'

#   declare the globals
sld = lung = fls = fln = Create (0)
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 Extreme 0.46"
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, n, sld, tgl, rtt, fls, fln

  # Button functions.
  Button ('Generate', 1, 50, 50, 200, 25)
  sld = Slider ('Grid size: ', 2, 50, 190, 200, 25, sld.val, 1.0, 10.0)
  tgl = Toggle ('Remove some objects?', 3, 50, 105, 200, 25, 0)
  rtt = Toggle ('Rotate objects?', 4, 50, 80, 200, 25, 0)
  fls = Slider ('Max floors: ', 5, 50, 130, 200, 25, fls.val, 1.0, 4.0)
  fln = Slider ('Tall houses: ', 6, 50, 155, 200, 25, fln.val, 0.0, (sld.val * sld.val))
   
  Button ('Button House', E_CUSTOM_BUTTON, 280, 410, 150, 25, E_CUSTOM_NAME)
  Button ('Slider House', E_CUSTOM_SLIDER, 280, 300, 150, 25, E_CUSTOM_NAME2)
  # EV 4:Debug must toggel on or off the debug print in the consol window.
  Toggle('Debug', 4, 280, 100, 100, 20, 1, 'toggle tip')
  Button ('Random Generate', E_RANDOM, 280, 255, 150, 25, E_RANDOM_NAME)
  
  # EV 7: Need to find a fix here to keep the last submitted slider house values.
  xC2 = Slider("xC ",7,50,380,200,25,dist.val,negfive.val,five.val,0,"Size of value X")
  yC2 = Slider("yC ",7,50,355,200,25,dist.val,negfive.val,five.val,0,"Size of value Y")
  hpC2 = Slider("hpC ",7,50,330,200,25,dist1.val,zero.val,five.val,0,"Size of value HP")
  hsC2 = Slider("hsC ",7,50,305,200,25,dist1.val,one.val,two.val,0,"Size of value HS")
  wC2 = Slider("wC ",7,50,280,200,25,dist3.val,two.val,four.val,0,"Size of value W")
  lC2 = Slider("lC ",7,50,255,200,25,dist3.val,two.val,four.val,0,"Size of value L")

  # EV 8: House Values for your Custom House.
  xC  = Number('X', 8, 50, 490, 100, 15, 1, -5, 5, 'X Value')
  yC  = Number('Y', 8, 50, 475, 100, 15, 1, -5, 5, 'Y Value')
  hpC = Number('HP', 8, 50, 460, 100, 15, 1, 0, 5, 'HP Value')
  hsC = Number('HS', 8, 50, 445, 100, 15, 1, 1, 2, 'HS Value')
  wC  = Number('W', 8, 50, 430, 100, 15, 2, 2, 4, 'W Value')
  lC  = Number('L', 8, 50, 415, 100, 15, 2, 2, 6, 'L Value')
  

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 == 8:
    # 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
  # Create a more detailed house woohoo
  if ev == 1:
    if (E_DEBUG == 1):
      print ">> Create a Detailed house with chimneys ...."
    make (sld.val, 1, tgl.val, rtt.val, fln.val, fls.val)
    return
  elif ev == 9:
    # 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))
    semiC2 = xC2 + (wC2/2)
    
    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    
      print "semi = ",semiC2
    
    CreateHouse(xC2, yC2, hpC2, hsC2, wC2, lC2, semiC2)
    return
  elif ev == 10:
    # 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

    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
    CreateHouse(x, y, hp, hs, w, l, semi)
    return
  elif ev == 11:
    # 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.
# Basic house mesh - i like to keep this as a option as well as the more detailed 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()


# New more detailed house maker function.
#   on to the good stuff...
def make (lim, dim, rem, rot, tal, etj):
   if (E_DEBUG == 1):
    print ">> Inside Make Function."
    print "x  = ",xC2
    print "y  = ",yC2
    print "hp = ",hpC2
    print "hs = ",hsC2
    print "w  = ",wC2
    print "l  = ",lC2
   dim = float (int(dim * 10)) / 10

   lun = 0.0
   lat = 0.0

   #   start defining the grid
   for gridy in range (lim):
      if (gridy != 0):
         lat = (dim + lat) + 1.5

      for gridx in range (lim):
         #   choose whether a mesh
         #   will be created or not
         if rem:
            rmv = int(Mathutils.Rand(0,20))
         else:
            rmv = 1

         if (rmv <= 13):

            #   define a new mesh
            mesh = NMesh.New()

            if (gridx != 0):
               lun = (dim + lun) + 1

            #   the random deviations
            rdm = float(int(Mathutils.Rand (3,7)) * 10) / 100
            rh = rdm + 0.1
            bln = float(int(Mathutils.Rand(0,1)) * 10) / 10
            if (bln < 1):
               rdm = rdm * (-1)
            hi = float(int(Mathutils.Rand (4,10)) * 10) / 100
            hi = dim * hi

            #   floors:
            if (tal):
               randhs = int(Mathutils.Rand (0,10))
               if (randhs <= 8):
                  #   will this house have many floors?
                  alt = float(int (Mathutils.Rand (1,(etj + 1)))) / 2
                  tal -= 1
               else:
                  alt = 0

            else:
               alt = 0                     

            #   start positioning the verts
            wid = dim + rdm
            len = (dim * 1.5) + rdm
            hei = alt + dim + rh
            a = NMesh.Vert (rdm,rdm,0)
            b = NMesh.Vert (wid,rdm,0)
            c = NMesh.Vert (wid,len,0)
            d = NMesh.Vert (rdm,len,0)
            e = NMesh.Vert (rdm,rdm,hei)
            f = NMesh.Vert (wid,rdm,hei)
            g = NMesh.Vert (wid,len,hei)
            h = NMesh.Vert (rdm,len,hei)
            i = NMesh.Vert ((rdm - 0.1),(rdm - 0.1),hei)
            j = NMesh.Vert ((wid + 0.1),(rdm - 0.1),hei)
            k = NMesh.Vert ((wid + 0.1),(len + 0.1),hei)
            l = NMesh.Vert ((rdm - 0.1),(len + 0.1),hei)
            m = NMesh.Vert ((rdm + (dim / 2)), (rdm + 0.15), (hei + hi))
            n = NMesh.Vert ((rdm + (dim / 2)), (len - 0.15), (hei + hi))

            #   and append them to the mesh
            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)
            mesh.verts.append (k)
            mesh.verts.append (l)
            mesh.verts.append (m)
            mesh.verts.append (n)

            #   then define the faces
            abcd = NMesh.Face ([d,c,b,a])
            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])
            efji = NMesh.Face ([e,f,j,i])
            fgkj = NMesh.Face ([f,g,k,j])
            ghlk = NMesh.Face ([g,h,l,k])
            heil = NMesh.Face ([h,e,i,l])
            ijm = NMesh.Face ([i,j,m])
            kln = NMesh.Face ([k,l,n])
            jknm = NMesh.Face ([j,k,n,m])
            limn = NMesh.Face ([l,i,m,n])

            #   and append them to the mesh
            mesh.faces.append (abcd)
            mesh.faces.append (abfe)
            mesh.faces.append (bcgf)
            mesh.faces.append (cdhg)
            mesh.faces.append (daeh)
            mesh.faces.append (efji)
            mesh.faces.append (fgkj)
            mesh.faces.append (ghlk)
            mesh.faces.append (heil)
            mesh.faces.append (ijm)
            mesh.faces.append (kln)
            mesh.faces.append (jknm)
            mesh.faces.append (limn)

            #   make chimneys
            number = int (Mathutils.Rand (0,3))
            for contor in range (number):
               ch = float (int (Mathutils.Rand (rdm,(wid - 0.1) * 100))) / 100
               ich = hei + hi + (Mathutils.Rand (0,0.5))
               randis = float (int (Mathutils.Rand(0,0.1) * 100)) / 100

               cha = NMesh.Vert (ch,ch,hei)
               chb = NMesh.Vert ((ch + 0.1),ch,hei)
               chc = NMesh.Vert ((ch + 0.1),(ch + 0.1 + randis),hei)
               chd = NMesh.Vert (ch,(ch + 0.1 + randis),hei)
               che = NMesh.Vert (ch,ch,ich)
               chf = NMesh.Vert ((ch + 0.1),ch,ich)
               chg = NMesh.Vert ((ch + 0.1),(ch + 0.1 + randis),ich)
               chh = NMesh.Vert (ch,(ch + 0.1 + randis),ich)
               chi = NMesh.Vert ((ch - 0.02),(ch - 0.02),ich)
               chj = NMesh.Vert ((ch + 0.12),(ch - 0.02),ich)
               chk = NMesh.Vert ((ch + 0.12),(ch + 0.12 + randis),ich)
               chl = NMesh.Vert ((ch - 0.02),(ch + 0.12 + randis),ich)
               chm = NMesh.Vert ((ch - 0.02),(ch - 0.02),(ich + 0.03))
               chn = NMesh.Vert ((ch + 0.12),(ch - 0.02),(ich + 0.03))
               cho = NMesh.Vert ((ch + 0.12),(ch + 0.12 + randis),(ich + 0.03))
               chp = NMesh.Vert ((ch - 0.02),(ch + 0.12 + randis),(ich + 0.03))

               mesh.verts.append(cha)
               mesh.verts.append(chb)
               mesh.verts.append(chc)
               mesh.verts.append(chd)
               mesh.verts.append(che)
               mesh.verts.append(chf)
               mesh.verts.append(chg)
               mesh.verts.append(chh)
               mesh.verts.append(chi)
               mesh.verts.append(chj)
               mesh.verts.append(chk)
               mesh.verts.append(chl)
               mesh.verts.append(chm)
               mesh.verts.append(chn)
               mesh.verts.append(cho)
               mesh.verts.append(chp)

               chabcd = NMesh.Face ([chd,chc,chb,cha])
               chabfe = NMesh.Face ([cha,chb,chf,che])
               chbcgf = NMesh.Face ([chb,chc,chg,chf])
               chcdhg = NMesh.Face ([chc,chd,chh,chg])
               chdaeh = NMesh.Face ([chd,cha,che,chh])
               chefji = NMesh.Face ([che,chf,chj,chi])
               chfgkj = NMesh.Face ([chf,chg,chk,chj])
               chghlk = NMesh.Face ([chg,chh,chl,chk])
               chheil = NMesh.Face ([chh,che,chi,chl])
               chijnm = NMesh.Face ([chi,chj,chn,chm])
               chjkon = NMesh.Face ([chj,chk,cho,chn])
               chklpo = NMesh.Face ([chk,chl,chp,cho])
               chlimp = NMesh.Face ([chl,chi,chm,chp])
               chmnop = NMesh.Face ([chm,chn,cho,chp])

               mesh.faces.append (chabcd)
               mesh.faces.append (chabfe)
               mesh.faces.append (chbcgf)
               mesh.faces.append (chcdhg)
               mesh.faces.append (chdaeh)
               mesh.faces.append (chefji)
               mesh.faces.append (chfgkj)
               mesh.faces.append (chghlk)
               mesh.faces.append (chheil)
               mesh.faces.append (chijnm)
               mesh.faces.append (chjkon)
               mesh.faces.append (chklpo)
               mesh.faces.append (chlimp)
               mesh.faces.append (chmnop)

            #   create the new mesh
            obj = Object.New ("Mesh", "House")
            obj.link (mesh)
            Scene.GetCurrent().link(obj)

            #   position the new mesh on the grid
            obj.setLocation (lun,lat,0)

            #   rotate the mesh
            if (rot):
               [rx, ry, rz] = obj.getEuler()
               rotate = float(int(Mathutils.Rand(0,9) * 10)) / 10
               rz += rotate
               obj.setEuler(rx,ry,rz)

            #   create the mesh
            Blender.Redraw()

      #   reset the x values of the grid
      lun = 0


Register (buton, exit, event)

If you make changes i think we should work from this updated version…

Great script. The only complaint that I have is that on my 800X600 screen some of the buttons at the top of the interface are too high and get cut off. I wish there was a way to zoom in and out of a script window created interface as there is with the regular button windown panel. Oh well that is probably a blender problem and not with your scripts. Once again gret script.

Could you please explain what each of the buttons and sliders do?

Once again. I REALLY like this script. I have been looking for something like this for years but PLEASE explain what each of thos buttons(like xp,xc yc ) are suppose to do. I hate it when somone submits a script without documenting it. Its like THEY WROTE the thing so they know how it works. How about explaining it to us other non programming souls.