Disperser

Python script that lets you choose values to randomizes the position and rotation of selected objects

import maya.cmds as mc

## Create window ##
dWin = mc.window	(
			title="Disperser", 
			wh=(150,100)
			)

mc.columnLayout()
mc.button(label="Disperse selected", command="fnDisperser()")

mc.text(label="Set X Y Z translate values (in units)")
rangeField = mc.floatFieldGrp(numberOfFields=3, cw3=(30,30,30))

mc.text(label="Set X Y Z rotate values (in degrees)")
rangeFieldrotate = mc.floatFieldGrp(numberOfFields=3, cw3=(30,30,30))

## Display window ##
mc.showWindow(dWin)

def fnDisperser():
	import random

	## Select all objects ##
	selList = mc.ls(sl=True)

	## Query floatfiledgrp ##
	rangeX = mc.floatFieldGrp(rangeField, query=True, value1=True)
	rangeY = mc.floatFieldGrp(rangeField, query=True, value2=True)
	rangeZ = mc.floatFieldGrp(rangeField, query=True, value3=True)

	rotateX = mc.floatFieldGrp(rangeFieldrotate, query=True, value1=True)
	rotateY = mc.floatFieldGrp(rangeFieldrotate, query=True, value2=True)
	rotateZ = mc.floatFieldGrp(rangeFieldrotate, query=True, value3=True)


	## Loop through selList ##
	for obj in selList:
		randomX = random.randint(-rangeX,rangeX)
		randomY = random.randint(-rangeY,rangeY)
		randomZ = random.randint(-rangeZ,rangeZ)

		randomXr = random.randint(-rotateX,rotateX)
		randomYr = random.randint(-rotateY,rotateY)
		randomZr = random.randint(-rotateZ,rotateZ)
	
		mc.setAttr(obj + ".translateX", randomX)
		mc.setAttr(obj + ".translateY", randomY)
		mc.setAttr(obj + ".translateZ", randomZ)

		mc.setAttr(obj + ".rotateX", randomXr)
		mc.setAttr(obj + ".rotateY", randomYr)
		mc.setAttr(obj + ".rotateZ", randomZr)
I wish to do something Great and Wonderful, but I must start by doing the little things like they were Great and Wonderful”
~ Albert Einstein