View Full Version : A loop to make this?

11 November 2008, 01:42 PM
Please please, could someone help :cry: :sad:

I'd like to run a loop on $n (any amount) number of polyspheres that will scale them evenly from 0 to 100% in scale. Could anyone point me in the right direction?? :lightbulb

Massive thanks in advance

11 November 2008, 02:24 PM
this doesnt create creat the shpere with a scale of 0 because i didnt see the point in that as you wouldnt see it but if you need it to do that let me know, also the scale is changed using the radius attr instead of scale just because it was quicker to wright

//replace the * with the number of spheres you want to create
int $n = *;
float $f = 1.0 / $n;
float $s = $f;

for ($i=0; $i<=$n; $i++)
polySphere -r $s;
$s += $f;

11 November 2008, 02:40 PM
Hi jaydru, thanks for your help. sorry Forgot to mention I already have the polyspheres made..

here's what I got ...

string $myselection[] = `ls -sl`;
int $numSelect = size($myselection);

int $t=0;

for( $t=0 ; $t<$numSelect ; $t++) {

float $sizBall = ($t+1)/$numSelect;

setAttr ($myselection + ".scaleX") $sizBall;
setAttr ($myselection + ".scaleY") $sizBall;
setAttr ($myselection + ".scaleZ") $sizBall;

//print( $t + " " + $b + "\n" );
print ($sizBall+ "\n" );

This has errors do you know why?

Thanks :)

also don't worry about scaling to zero. :)

11 November 2008, 03:04 PM
think the main problem is your trying to change the attr on the array $myselection, try this,
string $myselection[] = `ls -sl`;
int $numSelect = size($myselection);

float $sizeIcrament = 1.0/$numSelect;
float $size = $sizeIcrament;

for ($sel in $myselection)
setAttr ($sel + ".scaleX") $size;
setAttr ($sel + ".scaleY") $size;
setAttr ($sel + ".scaleZ") $size;
$size += $sizeIcrament;

11 November 2008, 03:18 PM
Thank you so much. Amazing stuff. :bounce: Sorry If my knowlege seems a little thin.
I'm so grateful for your help, thank you

Joe :)

11 November 2008, 05:28 PM
One last question!? :rolleyes:

If I wanted to use this but instead of just scaling the spheres I'd like to use a set driven key..

How would I write the syntax?

thx again :)

-currentDriver ($motionPathNode1 + ".uValue")
-driverValue 0.25
-attribute ???
-value ???? ;

11 November 2008, 11:17 AM
im not total sure what your trying to do if you can give a bit bit more of an explanation i might be able to help

11 November 2008, 11:34 AM
Sure, sorry.

I'd like to have the scale attribute of some polySpheres controlled by a controller object eg a Locator with a value from one going from zero to one. when the control moves from zero to one the polysphere move in a wave action.

see image attached, Thanks for your help :bowdown:

Also when the scale is zero or one the polysphere scale is 0 ie not visible

Basically I need a loop that will set an incremented set driven key value on each polySphere when the controller value is at .25 and the reverse when the value is .75

If I can explain further please say :)

11 November 2008, 05:53 PM
sorry about the no reply, been busy at work today,
im not sure if i can help you with this one, my knowledge of mel is quite basic,
is there a reason why you cant set the set driven key up manualy as opposed to doing it through mel?

11 November 2008, 07:28 PM
No worries jaydru, You've helped me a lot aready :)

My reason for not wanting to use Set Driven Keys manually is please I have around 500 groups of ten polyspheres to animate, doing this 5,000 time would do my head in!

Thanks so much for all your help


If anyone else has any ideas please let me know. :shrug:

11 November 2008, 11:28 PM
Hey this is just a basic idea, but maybe it works if you script the setdrivenkey setup with variables one time. You`d have to select all groups and it loops through every single one
and does the setup for you by grabbing and keying each of the 10 spheres in each group.

here`s the mel command for setdriven keys:

// To set the keyframe on the selected object's translateX based on
// curve1's rotateZ:
setDrivenKeyframe -at translateX -cd curve1.rz;

When you put in variables / select the objects with variables in a for loop then
move the objects to the desired positions and setDrivenKeyframe,
it might work out.

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