Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US :: FAQ
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE AFTER EFFECTS:HomeForumBasicsExpressionsTutorialsPodcastsAE TechniquesCreative Cloud DebateFAQ

Checkbox Control Expression

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Dmitriy DokhovCheckbox Control Expression
by on May 6, 2009 at 4:03:15 pm

Hi everybody,

I am a beginning After Effects user, and I am currently trying to create my own expression for the checkbox control. Actually, the way of doing it was fully described by Dan Ebberts in his tutorial: http://library.creativecow.net/articles/ebberts_dan/expression_cont.php (just look for "checkbox" passage). However, I think that creating my own expression (and comparing it with the expression described by the author) would be more useful for me in order to get my own After Effects experience.

I want my animation to run while the checkbox is on, hold at the current position while the checkbox is off and resume from where it left off when the checkbox comes on again. Here is my expression for time remapping:


timeoff = 0; // the amount of time when our checkbox switch is off
timeoff_old = 0;
switcher = thisComp.layer("Null 1").effect("Checkbox Control").param("Checkbox");

if (switcher > 0) // our switch is on
{if (switcher.valueAtTime(switcher.nearest_key(time).time)>0) /*if our nearest key is "on"
{x = (switcher.nearest_key(time).index)-1}
else // our nearest key is "off"
{x = switcher.nearest_key(time).index-2}
if (x > 0)
{timeoff_old = switcher.key(x+1).time - switcher.key(x).time;
timeoff+=timeoff_old;
a = time - timeoff}
else
{a=time}}
else
{a=0}
[a]

The expression looks for the nearest "off" and neighbour "on" key (their indexes are "x" and "x+1") and adds amount of time between these keys to the "timeoff" variable. It seems to work fine firstly, but when it comes to the second interval when the switch is "off", it does not add the previous "timeoff" value to the "timeoff" variable, i.e. "timeoff+=timeoff_old" does not work. I have no ideas why that happens, and it would be interesting for me to fix that error. Any help would be much appreciated. Thanks in advance.


Return to posts index
Reply   Like  

Dan EbbertsRe: Checkbox Control Expression
by on May 6, 2009 at 4:39:46 pm

Expressions have no memory of what has been calculated on prveious frames. All variables are wiped out. So.... your expression will have to go back and look at all the previous keyframes to figure out what the current value for time remapping should be.


Dan



Return to posts index
Reply   Like  

Dan EbbertsRe: Checkbox Control Expression
by on May 6, 2009 at 8:56:44 pm

I think this works:

c = effect("Checkbox Control")("Checkbox"); // checkbox

if (c.numKeys > 1){
n = c.nearestKey(time).index;
if (c.key(n).time > time) n--;
if ( n > 0){
accum = c.key(n).value * (time - c.key(n).time);
for (i = n; i > 0; i--){
if (i == 1){
accum += c.key(1).time * c.valueAtTime(0);
}else{
accum += c.key(i-1).value * (c.key(i).time - c.key(i-1).time);
}
}
}else{
accum = time*c.valueAtTime(0);
}
accum
}else{
time*c.valueAtTime(0);
}


Dan



Return to posts index
Reply   Like  


Dmitriy DokhovRe: Checkbox Control Expression
by on May 8, 2009 at 5:19:34 am

As I said, it is usually more difficult for me to understand somebody's expressions than to write my own ones. So after several attempts I finally modified my expression. I used a "Slider Control" effect in order to write down the duration of all "off" keyframes during my animation. Then I created a code that calculates all those "Slider" values:


timeoff = 0; // the amount of time when our checkbox switch is off
timeoff_old = 0; // this one has been transferred to a Slider Control
switcher = thisComp.layer("Null 1").effect("Checkbox Control").param("Checkbox");

if (switcher > 0) // our switch is on
{if (switcher.valueAtTime(switcher.nearest_key(time).time)>0) //if our nearest key is "on"
{x = (switcher.nearest_key(time).index)-1}// we need an index of the previous "off" switch
else // our nearest key is "off"
{x = switcher.nearest_key(time).index-2}
if (x > 0) // just fixing an error telling there is no keyframe number 0
{timeoff_old = switcher.key(x+1).time - switcher.key(x).time;
for (i=-1; i<=(x-2); i+=2)// we need to add the "timeoff_old" values during all the previous keyframes to "timeoff"
{timeoff+=effect("timeoff_old")("Slider").valueAtTime((switcher.key(x-i).time)+1/30)}// that's how we calculate all those values
a = time - timeoff}
else // if x = 0
{a=time}}
else
{a=0}

[a]

I am sure that Dan's code is more rational. Thanks a lot for your help and comment, Dan. I will now try to understand how your expression works, as well as the one described in your lesson.


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSFEATURESVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2014 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]