Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Trigger source text change with markers

  • Trigger source text change with markers

    Posted by Jonross Swaby on March 15, 2019 at 7:19 pm

    Hi,

    I have a text layer where the source text comes from a substring of the name of a layer in another comp. In this case it comes from the layer with the highest index value.

    I’d like to turn this into an expression whereby each marker will decrease the layer index by 1, and thus change the source text accordingly.

    Below is what I have so far. I don’t think I’m setting up the marker triggers correctly – to be honest I don’t fully understand what’s going in this part of the expression as I’ve just copied it from tutorials focusing on triggering position animations and the like.

    I’m finding that up until the first marker my source text just reads “1” and after that it reads as the first line of source text that I want, but doesn’t then update with subsequent markers.

    Can anyone please help?

    //set variables
    sc = comp("otherComp"); // source comp
    lc = sc.numLayers; // layer count of source comp
    idx = lc; // layer index;
    m = thisLayer.marker;

    //define function that updates text
    function upd() {idx = idx--};

    //marker triggers
    if (m.numKeys > 0) {
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    if (n > 0) {
    upd();
    sc.layer(idx).name.substr(3,sc.layer(idx).name.length);
    }}

    else {
    sc.layer(idx).name.substr(3,sc.layer(idx).name.length);
    }

    Jonross Swaby replied 7 years, 2 months ago 3 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    March 15, 2019 at 8:20 pm

    Variables don’t persist from frame to frame, so I don’t think your index scheme will work. I think you have all the info you need though, in variable n, which will be the count of how many markers you have passed, so you could do something like lc – n (I’m not sure exactly what you’re trying to do, but it should be close).

    Dan

  • Andrei Popa

    March 19, 2019 at 12:51 pm

    I am not completely sure what you want to achieve, but maybe this will help. This changes the source text to the layer name except the first 3 chars. Decreases index by one each time it passes a marker and starts with the last layer(before the first marker). No marker means that it takes the last layer.

    //set variables
    sc = comp("otherComp"); // source comp
    lc = sc.numLayers; // layer count of source comp
    m = thisLayer.marker;
    idx = lc; // layer index;
    m = thisLayer.marker;

    //marker triggers
    if (m.numKeys > 0) {
    n = m.nearestKey(time).index;
    if (time < m.key(n).time) n--;
    idx = lc - n;
    sc.layer(idx).name.substr(3, sc.layer(idx).name.length);
    } else {
    sc.layer(idx).name.substr(3, sc.layer(idx).name.length);
    }

    Andrei
    My Envato portfolio.

  • Jonross Swaby

    March 19, 2019 at 1:17 pm

    This does exactly what I want it to do – thanks Andrei!

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