Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions valueAtTime() on a REGEX Text Layer

  • valueAtTime() on a REGEX Text Layer

  • David Avila

    January 9, 2022 at 8:02 am

    Hi,

    I know that valueAtTime only works on Properties, but I was wondering if there was a way to use Dan Ebbert’s timeRemap expression to trigger animations using a TextLayer which has undergone REGEX editing?

    The idea is that the Text Layer in question is ‘1’ only a few frames (it gets checked each frame).

    ...
    var P2Output = P2Str.replace(Px_ValueExp , '').split(',')[0]; // Regex + Split. Will change from 0 to 1.
    
    // Original Script by Dan Ebberts | Apply to timeRemap
    txt = P2Output;
    t = 0;
    f = timeToFrames(time);
    
    if (txt == 1)
    {
      t = time;
      while (f >= 0)
      {
        if (txt.valueAtTime(framesToTime(f)) == 0) // the line that returns an error
    	{
          t = time - framesToTime(f);
          break;
        }
        f--;
      }
    }
    t

    Normally this returns an error as the text-layer changes to a String. I was wondering, if we knew that P2Output will equal to 1 for only a few frames, could we trigger a layer's animation while P2Output = 1?

  • Dan Ebberts

    January 9, 2022 at 6:10 pm

    It’s not clear to me exactly what you’re trying to do, but if variable txt is a string, it seems like you should either use parseInt(txt,10) to convert it to a number, or change your conditional tests to look for characters (“0” or “1”) rather than numbers (0 or 1) .

    Dan

  • David Avila

    January 9, 2022 at 6:21 pm

    Well, valueAtTime() doesn’t work with strings or ints. IIRC, it has to be done on a property. My initial text layer is a whole paragraph which I truncate using REGEX — once I do that, valueAtTime() doesn’t work on the reference anymore.

    I’m trying to initialize a pre-comp’s animation whenever this text layer is ‘`1’, otherwise, freeze the pre-comp at 0:00. I believe in order to do this, valueAtTime() is necessary for the while-loop to work.

  • Andrei Popa

    January 9, 2022 at 8:06 pm

    I think that on the error line, you use .valueAtTime() on a string. I think you should use .valueAtTime() first, then apply the regex+split. So get the sourceText property first, apply .valueaAtTime, then apply your replace(or any function that you want to apply to the string)

  • David Avila

    January 10, 2022 at 7:11 pm

    The two master-variables are being calculated every frame, so I was wondering how I would re-write the script to use them somehow. I just need for the comp’s timeRemap to jump and play from 0:00 while the value is true…Something like this:

    Edit, I figured it out but I was wondering if someone could please break down the way the while-loop works. A friend and I were talking about it and it’s kinda confusing, thank you.

    The expression:

    var masterEval = thisComp.layer("MasterEvalFunction").text.sourceText; var masterResult = masterEval.includes("P2_Being_Hit: 1"); // Original Script by Dan Ebberts txt = masterEval; t = 0; f = timeToFrames(time); if ( masterResult ) { t = time; while (f >= 0) { if ( !txt.valueAtTime(framesToTime(f) ).includes("P2_Being_Hit: 1") ) { t = time - framesToTime(f); break; } f--; } } t

  • Dan Ebberts

    January 10, 2022 at 8:51 pm

    The while loop just starts at the current frame, and goes back in time, frame by frame, until it finds the most recent frame where the text included the target phrase. It then sets variable t to how long ago that occurred.

  • David Avila

    January 10, 2022 at 9:12 pm

    I see!

    A friend reduced the expression down quite a bit:

    time - (function(f){
        while(f-- >= 0) if(!thisComp.layer("MasterEvalFunction").text.sourceText.valueAtTime(framesToTime(f+1)).includes("P2_Being_Hit: 1")) return framesToTime(f+1);
    })(timeToFrames(time))
Viewing 1 - 7 of 7 posts

Log in to reply.

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