Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Triggering an animation using a Text Layer Value

  • Triggering an animation using a Text Layer Value

  • David Avila

    June 7, 2021 at 8:08 am

    Hello,

    I have a series of if-else statements whose results are written in a Text Layer. For instance “On” / “Off”.

    I was wondering if I could use “On” to initiate and trigger an animation to play in its entirety (either on the same layer or a different one).

    Thank you

  • Dan Ebberts

    June 7, 2021 at 4:52 pm

    Something like this maybe:

    txt = thisComp.layer("Text").text.sourceText;

    t = 0;

    if (txt == "On"){

    f = timeToFrames(time);

    t = time;

    while (f >= 0){

    if (txt.valueAtTime(framesToTime(f)) == "Off"){

    t = time - framesToTime(f);

    break;

    }

    f--;

    }

    }

    t

  • David Avila

    June 7, 2021 at 8:18 pm

    Thanks!

    I applied the expression to a pre-compsed layer’s Time Remapping expression. My pre-composed layer’s animation begins at 0 and whenever my Text Layer reads “On”, it begins to play the animation as long as the Text Layer says “On”. When the Text Layer goes to “Off”, the Time Remapping value goes back to 0.

    I believe I get most of it until the ‘break’ and the subtraction from ‘f’. Break terminates the while-loop after setting ‘t’ to 0 in the previous line? Subtracting one from ‘f’ is allowing the animation to increase by 1 frame at a time, right; it’s creating the 1 frame offset between the time remap’s value and the composition playhead value?

    I don’t know if it’s uncouth to post my own renamed and commented version of your script on here?

  • Dan Ebberts

    June 7, 2021 at 9:46 pm

    <div>It sounds like maybe you’re after something very different than what I posted. This is a version that should run your time remapped comp animation as long as the text is “On”, hold the last value when the text goes “Off”, and start again (not from zero, but from the held time) if it goes “On” again:</div>

    txt = thisComp.layer("Text").text.sourceText;

    n = 0;

    for (f = 0; f < timeToFrames(time); f++){

    if (txt.valueAtTime(framesToTime(f)) == "On"){

    n++;

    }

    }

    framesToTime(n);

    >I don’t know if it’s uncouth to post my own renamed and commented version of your script on here?

    Not an issue.

  • David Avila

    June 7, 2021 at 10:05 pm

    Actually, the first one is what I wanted. I should have mentioned it, but it’s just going to be a simple animation like a strobe that blinks on and off while the text is “On”, and then resets or disappears when it’s “Off”.

    In this new case, it holds it in its last position from before. I added an “else {n =0}” to your if-statement to reset it back to 0 so that it can replay once “On” comes up again.

    This is my version of your first script with the attendant comments:

    textResult = thisComp.layer("is_On_or_Off?").text.sourceText

    thisLayerTimeRemap = 0; // thisLayer = Pre-composed layer whose animation starts at 0:00

    if (textResult == "On"){

    thisLayerTimeRemap = time; // sets pre-composed layer's time remap value equal to this composition's time value

    playheadValue = timeToFrames(time); //this composition's playhead-value/time converted to frames

    while (playheadValue >= 0){

    if (textResult.valueAtTime(framesToTime(playheadValue)) == "Off"){ // checks if text-result says "Off"

    thisLayerTimeRemap = time - framesToTime(playheadValue); // keeps its value at zero as time advances

    break; // after setting the time-remap to 0, breaks out of the loop

    }

    playheadValue--; // subtracts 1 frame the playhead's time-value in order to move the animation forward by one frame.

    }

    }

    thisLayerTimeRemap // outputs the result of this layer's Time Remap value

Viewing 1 - 5 of 5 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy