PDA

View Full Version : Duplicate Objects and Move Them


pradeepmamgain
10-01-2009, 06:59 AM
I have few locators in the scene and a nurbs sphere, I want to first duplicate the sphere and then move the sphere to the locator's position.

I am trying following code but it is not working, please help...


float $y=0;
float $x=0;
float $z=0;
$selected=`ls -sl`;
for ($selObj in $selected)
{
$x=`getAttr $selObj.tx`;
$y=`getAttr $selObj.ty`;
$z=`getAttr $selObj.tz`;

setAttr "nurbsSphere1.tx" $x;
setAttr "nurbsSphere1.tx" $y;
setAttr "nurbsSphere1.tx" $z;
}

jaydru
10-01-2009, 11:24 AM
try this, select locators then select obj and run

$nodes = `ls -sl`;
$obj = $nodes[size($nodes)-1];

for ($loc in $nodes)
{
if ($loc == $obj)
break;

$pnt = `pointPosition $loc`;
$dup = `duplicate $obj`;
xform -ws -t $pnt[0] $pnt[1] $pnt[2] $dup[0];
}
delete $obj;

pradeepmamgain
10-01-2009, 11:45 AM
Its not working still. I have 5 locators and a nurbsSphere. I want to duplicate the sphere and then move that sphere to locator1's position. I want it in loop for all the selected sphere.

Thanks...

jaydru
10-01-2009, 01:28 PM
should work i just tested it then, do you have them selected in the right order (first select locs then shift select sphere then run the script, if so did you get an error and line number?

CGTalk Moderation
10-01-2009, 01:28 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.