ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Trigger source text change with markers

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Jonross Swaby
Trigger source text change with markers
on Mar 15, 2019 at 7:19:07 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 &lt; 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);
}


Return to posts index

Dan Ebberts
Re: Trigger source text change with markers
on Mar 15, 2019 at 8:20:47 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



Return to posts index

Andrei Popa
Re: Trigger source text change with markers
on Mar 19, 2019 at 12:51:17 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.


Return to posts index


Jonross Swaby
Re: Trigger source text change with markers
on Mar 19, 2019 at 1:17:46 pm

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


Return to posts index

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