BernieMelLibrary

From bernie's
Jump to: navigation, search
// sorts objects between the first and the last of the selection
//
global proc arrange(){
	string $sel[] = `ls -sl`;
	$first = $sel[0];
	$size = size($sel);
	$last = $sel[$size-1];
	float $firstTr[] = `xform -q -r -t $first`;
	float $firstRt[] = `xform -q -r -ro $first`;
	float $firstSl[] = `xform -q -r -s $first`;
	float $lastTr[] = `xform -q -r -t $last`;
	float $lastRt[] = `xform -q -r -ro $last`;
	float $lastSl[] = `xform -q -r -s $last`;
	for($a = 0; $a<$size;$a++){
		$r = ($a*1.0)/($size-1);
		//super beau code  \o/
		setAttr ($sel[$a]+".translateX") ($firstTr[0]+$r*($lastTr[0]-$firstTr[0]));
		setAttr ($sel[$a]+".translateY") ($firstTr[1]+$r*($lastTr[1]-$firstTr[1]));
		setAttr ($sel[$a]+".translateZ") ($firstTr[2]+$r*($lastTr[2]-$firstTr[2]));
		setAttr ($sel[$a]+".rotateX") ($firstRt[0]+$r*($lastRt[0]-$firstRt[0]));
		setAttr ($sel[$a]+".rotateY") ($firstRt[1]+$r*($lastRt[1]-$firstRt[1]));
		setAttr ($sel[$a]+".rotateZ") ($firstRt[2]+$r*($lastRt[2]-$firstRt[2]));
		setAttr ($sel[$a]+".scaleX") ($firstSl[0]+$r*($lastSl[0]-$firstSl[0]));
		setAttr ($sel[$a]+".scaleY") ($firstSl[1]+$r*($lastSl[1]-$firstSl[1]));
		setAttr ($sel[$a]+".scaleZ") ($firstSl[2]+$r*($lastSl[2]-$firstSl[2]));
	}
}