PDA

View Full Version : A loop to make this?


johnjoe
11-04-2008, 12: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

jaydru
11-04-2008, 01: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;
}

johnjoe
11-04-2008, 01: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. :)

jaydru
11-04-2008, 02: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;
}

johnjoe
11-04-2008, 02: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 :)

johnjoe
11-04-2008, 04: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 :)

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

jaydru
11-05-2008, 10: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

johnjoe
11-05-2008, 10: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 :)

jaydru
11-05-2008, 04: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?

johnjoe
11-05-2008, 06: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

Joe

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

Inlakechh
11-05-2008, 10: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-05-2008, 10: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.