PDA

View Full Version : Need improvement on that Replace "copy to instance" script.


smoluck
10-06-2010, 11:29 AM
Hello.

I'm searching some improvement on that script. Sometimes you need to replace simple object by another as an instanced one, This script was designed for that and it was usefull since many years, but now as I've didn't take care about the scale attribute, it didn't work with obect with different scale.
Now i need to get the scale value on the result.

Select one or more object that were not instanced from any object and at last, select the object you want to instance at there position.


{
string $selObjs[] = `ls -sl` ; // all of the selected
int $count = `size($selObjs)` ; // how many selected?
int $second2last = $count-1 ;
string $dup = $selObjs[$second2last] ; // last selected
float $pos[] , $rot[] ;
int $i ;
string $instanz ;
string $tmp[] ;

// for every item in the selection list DO:
for ( $i = 0 ; $i < $second2last ; $i++ )
{
clear $pos ; clear $rot ; // make sure no old values are still stored here
$tmp = `duplicate -ilf $dup` ; // duplicate the last object 1 time
$instanz = $tmp[0] ; // trick; duplicate returns an array, but we only need the very 1st one
$pos = `xform -q -ws -t $selObjs[$i]` ; // get the position of the item to clone
$rot = `xform -q -ws -ro $selObjs[$i]` ; // get the rotation as well
xform -ws -t $pos[0] $pos[1] $pos[2] $instanz ; // set the instance to that position
xform -ws -ro $rot[0] $rot[1] $rot[2] $instanz ; // set the rotation as well
delete $selObjs[$i] ; // delete the 'wrong' object
}
}

This script was ok for return good position and rotation from the target an get good result. But I need feature in order get the scale attribute back. At this time if i create multiple object at different location, with different rotation and scale, i can't get back the scale on the result.

Replacing the -ro or -t by -s ,-sca or -scale didn't work at all. how can i fix that feature ?

mduvekot
10-06-2010, 02:30 PM
{
string $selObjs[] = `ls -sl` ; // all of the selected
int $count = `size($selObjs)` ; // how many selected?
int $second2last = $count-1 ;
string $dup = $selObjs[$second2last] ; // last selected
float $pos[] , $rot[] ;
int $i ;
string $instanz ;
string $tmp[] ;

// for every item in the selection list DO:
for ( $i = 0 ; $i < $second2last ; $i++ )
{
clear $pos ; clear $rot ; // make sure no old values are still stored here
$tmp = `duplicate -ilf $dup` ; // duplicate the last object 1 time
$instanz = $tmp[0] ; // trick; duplicate returns an array, but we only need the very 1st one
$pos = `xform -q -ws -t $selObjs[$i]` ; // get the position of the item to clone
$rot = `xform -q -ws -ro $selObjs[$i]` ; // get the rotation as well
$scl = `xform -q -os -r -s $selObjs[$i]` ; // get the scale as well
xform -ws -t $pos[0] $pos[1] $pos[2] $instanz ; // set the instance to that position
xform -ws -ro $rot[0] $rot[1] $rot[2] $instanz ; // set the rotation as well
xform -os -s $scl[0] $scl[1] $scl[2] $instanz ; // set the scale as well
delete $selObjs[$i] ; // delete the 'wrong' object
}
}

smoluck
10-07-2010, 09:04 AM
Thanks a lot mduvekot.

How do i fix that message ?

// Warning: Cannot query scale in worldspace. Defaulting to local space. //

Should I need to replace -ws by -ls for the scale line ?

mduvekot
10-07-2010, 10:36 AM
-os for objectSpace, yes. You'll also want to add -r for relative.

CGTalk Moderation
10-07-2010, 10:36 AM
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.