ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Get a slider to be certain values at certain times

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Leo Menezes
Get a slider to be certain values at certain times
on Jul 17, 2020 at 6:07:40 am

Hello! First time using this platfom. Would really apreciate if somewone could help.

So, I have a slider (slider 1) that is getting values from a TXT, and each frame it has one value. For example, at frame 1 it it 22, at frame 2 it is 36, at frame 3 it is 55, and so on.
I need to get another slider (slider 2) to keep that value (22, for example) for that given ammont of frames.
So, finally, the slider 2 would show the value 22 for the first 22 frames, and then change its value to 36 for another 36 frames, and so on.
What I have at the momment is expression inside the slider 2. It makes the first transition (value 22 for 22 frames, and then changes value to 36), but it does not loop for the next values. Could someone please help me understand why? I'm a newbie at expressions.

var y = 0;
contframes = framesToTime(y);
tc = effect("slider 1")("Slider").valueAtTime(contframes);
if (time &lt; tc) {
x = tc;
}
else {
y = y + 1;
contframes = framesToTime(y);
tc = effect("slider 1")("Slider").valueAtTime(contframes);
x = tc;
}
x


Return to posts index

Filip Vandueren
Re: Get a slider to be certain values at certain times
on Jul 17, 2020 at 10:24:05 am

It would be optimal if the 2nd slider also refers back to the original text instead of to the first slider.
That way the expression gets all the values in 1 go instead of having to scan through time to read every possible value from Slidr 1

How did you get the numbers from the txt? In my example, I have a textlayer with 1 number per line and use the split("\r") command to change it into an array:


values=thisComp.layer("values").text.sourceText.value.split("\r");
f = timeToFrames(time);
sum = (acc,cur) => parseFloat(acc)+parseFloat(cur);

i=1;
while ( i= values.slice(0,i).reduce(sum) ) {
i++;
}
values[i-1];




Return to posts index

Filip Vandueren
Re: Get a slider to be certain values at certain times
on Jul 17, 2020 at 10:33:32 am

Sorry, code was mangled because of lesser than and greater than symbols:


values=thisComp.layer("values").text.sourceText.value.split("\r");
f = timeToFrames(time);
sum = (acc,cur) => parseFloat(acc)+parseFloat(cur);

i=1;

while ( i<values.length && f >= values.slice(0,i).reduce(sum) ) {
i++;
}
values[i-1];




Return to posts index


Leo Menezes
Re: Get a slider to be certain values at certain times
on Jul 17, 2020 at 2:04:00 pm

Wow, thanks a bunch, Filip! It worked like a charm! I still didn't understand exactly how it work, but I'll study it.
The source is a .txt tabulated file generated from and excel sheet. I could manage to isolate just the data I needed.

Thanks again!
Leo Menezes


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]