January 28, 2008
replace.mel
//e.g. suppose we have 1 box and several spheres scattered all over the scene.
// now i want to replace all spheres with box so i select box first and then all spheres.
//now execute the script.
{
string $f_obj; //first obj
string $obj; //temp obj
string $sel_objs[]=`ls -sl`; //get all sellected objects
int $tot_objs= size($sel_objs); //get number of objs
float $trans_xyz[3]; // store co-ordinates x,y & z .
string $dup_obj[];
if($tot_objs>=2){
int $i;
$f_obj = $sel_objs[0];// 1st obj in selected list
for($i=1;$i<$tot_objs;$i++)
{
$obj = $sel_objs[$i];
$trans_xyz[0]= `getAttr ($obj +".translateX")`;
$trans_xyz[1]= `getAttr ($obj +".translateY")`;
$trans_xyz[2]= `getAttr ($obj +".translateZ")`;
$dup_obj=`duplicate $f_obj`;
move -xyz $trans_xyz[0] $trans_xyz[1] $trans_xyz[2] $dup_obj;
delete $obj;
}
headsUpMessage(($i-1) + " objects replaced.");
}
else{ headsUpMessage("Select 2 or more objects.");}
}




