Randomizer script (v.35, 31-8-2004)

Z-loc and Z-rot bug fixed
I made this script, originaly for myself, but I exstended it a bit and though maybe it would be to use of someone. The script can random the lcation and size of objects, axes separate or together. Designed for Windows XP.

######################### 
# Randomizer script v.35 
#   by ThePatrickP 
# 
# 30-8-2004 
# 
# v.10: Gui created, draw 
# and standard code 
# v.20: Added main code 
# v.30: Added separate X, 
# Y & Z and size 
# v.33: Added same buttons
# v.35: Added rotation 
# 
######################### 

#!BPY 
""" 
Name: 'Randomizer' 
Blender: 234 
Group: 'Misc' 
Tip: 'Randomize Location and Size' 
""" 

import Blender 
from Blender import Noise 
import math 
from math import ceil 
from Blender.BGL import * 
from Blender.Draw import * 

Minr = Create(0.0) 
Maxr = Create(1.0) 
LocXr = Create(0) 
LocYr = Create(0) 
LocZr = Create(0)
RotXr = Create(0) 
RotYr = Create(0) 
RotZr = Create(0)  
SizeXr = Create(0) 
SizeYr = Create(0) 
SizeZr = Create(0) 
SameLr = Create(0) 
SameRr = Create(0) 
SameSr = Create(0) 

EVENT_NOEVENT = 1 
EVENT_RANDOM  = 2 
EVENT_EXIT    = 3 

def draw(): 
	global Minr, Maxr 
	global LocXr, LocYr, LocZr
	global RotXr, RotYr, RotZr
	global SizeXr, SizeYr, SizeZr 
	global SameLr, SameRr, SameSr 
	global EVENT_NOEVENT, EVENT_RANDOM, EVENT_EXIT 

	glClear(GL_COLOR_BUFFER_BIT) 
	glRasterPos2d(10, 200) 
	Text("Randomizer script") 
	glRasterPos2d(10, 110) 
	Text("Location:")
	glRasterPos2d(10, 80) 
	Text("Rotation:") 
	glRasterPos2d(10, 50) 
	Text("Size:") 
	Minr = Number("Minimal", EVENT_NOEVENT, 10, 170, 120, 20, 
		Minr.val, -1000, 1000, "The minimal random number");
	Maxr = Number("Maximal", EVENT_NOEVENT, 10, 140, 120, 20, 
		Maxr.val, -1000, 1000, "The maximal random number"); 
	LocXr = Toggle("X", 10, 70, 110, 20, 20, LocXr.val, "Randomizes X location"); 
	LocYr = Toggle("Y", 10, 90, 110, 20, 20, LocYr.val, "Randomizes Y location"); 
	LocZr = Toggle("Z", 10, 110, 110, 20, 20, LocZr.val, "Randomizes Z location");
	RotXr = Toggle("X", 10, 70, 80, 20, 20, RotXr.val, "Randomizes X rotation"); 
	RotYr = Toggle("Y", 10, 90, 80, 20, 20, RotYr.val, "Randomizes Y rotation"); 
	RotZr = Toggle("Z", 10, 110, 80, 20, 20, RotZr.val, "Randomizes Z rotation");
	SizeXr = Toggle("X", 10, 70, 50, 20, 20, SizeXr.val, "Randomizes X size"); 
	SizeYr = Toggle("Y", 10, 90, 50, 20, 20, SizeYr.val, "Randomizes Y size"); 
	SizeZr = Toggle("Z", 10, 110, 50, 20, 20, SizeZr.val, "Randomizes Z size"); 
	SameLr = Toggle("Same", 10, 140, 110, 40, 20, SameLr.val, "Use same number for all directions");
	SameRr = Toggle("Same", 10, 140, 80, 40, 20, SameRr.val, "Use same number for all directions"); 
	SameSr = Toggle("Same", 10, 140, 50, 40, 20, SameSr.val, "Use same number for all directions"); 
	Button("Randomize", EVENT_RANDOM, 10, 10, 80, 18) 
	Button("Exit", EVENT_EXIT, 100, 10, 80, 18) 

def event(evt, val):    
	if (evt == QKEY and not val): 
		Exit() 

def bevent(evt): 
	global Minr, Maxr 
	global LocXr, LocYr, LocZr
	global RotXr, RotYr, RotZr
	global SizeXr, SizeYr, SizeZr 
	global SameLr, SameRr, SameSr 
	global EVENT_NOEVENT, EVENT_RANDOM, EVENT_EXIT 

	if (evt == EVENT_EXIT): 
		Exit() 
	elif (evt == EVENT_RANDOM): 
		Randomize(Minr, Maxr, LocXr, LocYr, LocZr, RotXr, RotYr, RotZr, SizeXr, SizeYr, SizeZr, SameLr, SameRr, SameSr) 
		Blender.Redraw() 
Register(draw, event, bevent) 

def Randomize(fMinr, fMaxr, fLocXr, fLocYr, fLocZr, fRotXr, fRotYr, fRotZr, fSizeXr, fSizeYr, fSizeZr, fSameLr, fSameRr, fSameSr): 
	selobj = Blender.Object.GetSelected()
	for obj in selobj:
		if (fLocXr.val == 1): 
			newxloc = (Getnumr(fMinr, fMaxr)) + obj.getLocation()[0] 
		else: 
			newxloc = obj.getLocation()[0] 
		if (fLocYr.val == 1): 
			newyloc = (Getnumr(fMinr, fMaxr)) + obj.getLocation()[1] 
		else: 
			newyloc = obj.getLocation()[1] 
		if (fLocZr.val == 1): 
			newzloc = (Getnumr(fMinr, fMaxr)) + obj.getLocation()[2] 
		else: 
			newzloc = obj.getLocation()[2]
		if (fRotXr.val == 1): 
			newxrot = (Getnumr(fMinr, fMaxr)) + obj.getEuler()[0] 
		else: 
			newxrot = obj.getEuler()[0] 
		if (fRotYr.val == 1): 
			newyrot = (Getnumr(fMinr, fMaxr)) + obj.getEuler()[1] 
		else:
			newyrot = obj.getEuler()[1] 
		if (fRotZr.val == 1): 
			newzrot = (Getnumr(fMinr, fMaxr)) + obj.getEuler()[2] 
		else: 
			newzrot = obj.getEuler()[2] 
		if (fSizeXr.val == 1): 
			newxsize = (Getnumr(fMinr, fMaxr)) + obj.getSize()[0] 
		else: 
			newxsize = obj.getSize()[0] 
		if (fSizeYr.val == 1): 
			newysize = (Getnumr(fMinr, fMaxr)) + obj.getSize()[1] 
		else: 
			newysize = obj.getSize()[1] 
		if (fSizeZr.val == 1): 
			newzsize = (Getnumr(fMinr, fMaxr)) + obj.getSize()[2] 
		else: 
			newzsize = obj.getSize()[2] 
		if (fSameLr.val == 1): 
			if (fLocXr.val == 1): 
				newyloc = newxloc - obj.getLocation()[0] + obj.getLocation()[1] 
				newzloc = newxloc - obj.getLocation()[0] + obj.getLocation()[2] 
			elif (fLocYr.val == 1): 
				newzloc = newyloc - obj.getLocation()[1] + obj.getLocation()[2]
		if (fSameRr.val == 1):
			if (fRotXr.val == 1): 
				newyrot = newxrot - obj.getEuler()[0] + obj.getEuler()[1] 
				newzrot = newxrot - obj.getEuler()[0] + obj.getEuler()[2] 
			elif (fRotYr.val == 1): 
				newzrot = newyrot - obj.getEuler()[1] + obj.getEuler()[2]
		if (fSameSr.val == 1): 
			if (fSizeXr.val == 1): 
				newysize = newxsize - obj.getSize()[0] + obj.getSize()[1] 
				newzsize = newxsize - obj.getSize()[0] + obj.getSize()[2] 
			elif (fSizeYr.val == 1): 
				newzsize = newysize - obj.getSize()[1] + obj.getSize()[2] 
		obj.setLocation(newxloc, newyloc, newzloc)
		obj.setEuler(newxrot, newyrot, newzrot)  
		obj.setSize(newxsize, newysize, newzsize)
	Blender.Redraw() 
def Getnumr(min, max):    
	numr = Noise.random() 
	numr = numr * ((max.val - min.val) * 1000) 
	numr = math.ceil(numr) 
	numr = numr + (min.val * 1000) 
	numr = numr / 1000 
	return numr

CC welcome

Designed for Winblows XP! Yuck!

Designed for Winblows XP! Yuck!

sounds like a certain jackass is looking to get flammed :wink:


dig the idea of the script. Ill try it out asap.

Doesn’t it work on your OS? > which?

Works pretty cool! I can make a ton of objects, select them all and it randomizes each one differently. Well done and thanks!

Don’t let these guys harass you about XP, they just refuse to comply!

One of us one of us one of us.