PDA

View Full Version : number of objects in a list.


JockeP
11-02-2008, 08:31 PM
I made a script that will transfer the pivot for one object to another. What I would like to know is how to find out how many objects I have selected. That would make the script better :) Here is the script

string $selection[] = `ls -sl`;
float $SPx = `getAttr ($selection[0] +".scalePivotX")`;
float $SPy = `getAttr ($selection[0] +".scalePivotY")`;
float $SPz = `getAttr ($selection[0] +".scalePivotZ")`;
float $RPx = `getAttr ($selection[0] +".rotatePivotX")`;
float $RPy = `getAttr ($selection[0] +".rotatePivotY")`;
float $RPz = `getAttr ($selection[0] +".rotatePivotZ")`;

int $i=0;
for ($i;$i<5;$i++)
{
setAttr ($selection[$i] +".scalePivotX") ($SPx);
setAttr ($selection[$i] +".scalePivotY") ($SPy);
setAttr ($selection[$i] +".scalePivotZ") ($SPz);
setAttr ($selection[$i] +".rotatePivotX") ($RPx);
setAttr ($selection[$i] +".rotatePivotY") ($RPy);
setAttr ($selection[$i] +".rotatePivotZ") ($RPz);
}

This will only work on 5 objects(or whatever number you set it to). And you will also need to select the object you want to transfer the pivot from first. And if I knew how to find out how many objects you select, I could make it work for every object selected and you could also select the object that you wish to have the pivot from last.

gaggle
11-02-2008, 09:58 PM
Wouldsize($selection) cover your needs?

JockeP
11-03-2008, 03:01 AM
Yeah it wors like a charm, thanks gaggle

string $selection[] = `ls -sl`;
int $antal = size($selection);
int $last = ($antal-1);
float $SPx = `getAttr ($selection[$last] +".scalePivotX")`;
float $SPy = `getAttr ($selection[$last] +".scalePivotY")`;
float $SPz = `getAttr ($selection[$last] +".scalePivotZ")`;
float $RPx = `getAttr ($selection[$last] +".rotatePivotX")`;
float $RPy = `getAttr ($selection[$last] +".rotatePivotY")`;
float $RPz = `getAttr ($selection[$last] +".rotatePivotZ")`;

int $i=0;
for ($i;$i<$last;$i++)
{
setAttr ($selection[$i] +".scalePivotX") ($SPx);
setAttr ($selection[$i] +".scalePivotY") ($SPy);
setAttr ($selection[$i] +".scalePivotZ") ($SPz);
setAttr ($selection[$i] +".rotatePivotX") ($RPx);
setAttr ($selection[$i] +".rotatePivotY") ($RPy);
setAttr ($selection[$i] +".rotatePivotZ") ($RPz);
}

CGTalk Moderation
11-03-2008, 03:01 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.