Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Using markers to drive position from one variable position to multiple others

  • Using markers to drive position from one variable position to multiple others

    Posted by Beau McCombs on July 24, 2020 at 11:08 pm

    I suck at expressions. I’ve copied an expression from EC Abrams in order to make shape layers scale to the size of text, but other than that, I just kind of winged it. Here’s what I have so far:

    I’ve created a series of boxes (shape layers), each having an expression to size them to the text within the box.

    Each box is parented to the first box, and the position of each box will change to keep the box relative to the box to the left of it, so if the text on box one changes, the size of that box expands, as well as moves all the boxes over.

    I’ve now created a master movement null, and separated the x and y layers, as I only need to move on the x axis.

    In that parameter, I’ve created a series of variables calculating the distance of each box from each other so that if I type at the bottom of the expression: “position 3”, all of the boxes will move to the left, and the 3rd box is directly in the center of the comp.

    Here’s what it looks like right now : https://imgur.com/a/KCmSlUq. I know it’s probably too much variables/clutter, I’m not really good at this, but it works.

    What I’d like to do is create an expression so that each time the playhead crosses a marker (or even as it crosses each second), it will ease (maybe over 12 frames) from position 1 to Position 2, then on the next marker from position 2 to position 3, and so on until box 10. Again, the reason I created the expression is that the text in each box can and will change on different projects, so these positions are all variable.

    I’m guessing this is an If/Then expression, but I’ve found them to be confusing, and I didn’t know how to have multiple options within it so it would flow from each position to the next. I’ve been watching tutorials, and it just isn’t clicking. Could you lend a hand?

    Thanks in advance!

    d1 = (thisComp.layer("TextBox 1").content("Rectangle 1").content("Rectangle Path 1").size[0]/2) ;
    d2 = (thisComp.layer("TextBox 2").position[0]) ;
    d3 = (thisComp.layer("TextBox 3").position[0]) ;
    d4 = (thisComp.layer("TextBox 4").position[0]) ;
    d5 = (thisComp.layer("TextBox 5").position[0]) ;
    d6 = (thisComp.layer("TextBox 6").position[0]) ;
    d7 = (thisComp.layer("TextBox 7").position[0]);
    d8 = (thisComp.layer("TextBox 8").position[0]);
    d9 = (thisComp.layer("TextBox 9").position[0]);
    d10 = (thisComp.layer("TextBox 10").position[0]);

    move1 = d1;
    move2 = d1 + d2;
    move3 = d1 + d3;
    move4 = d1 + d4;
    move5 = d1 + d5;
    move6 = d1 + d6;
    move7 = d1 + d7;
    move8 = d1 + d8;
    move9 = d1 + d9;
    move10 = d1 + d10;

    pos1 = value - move1;
    pos2 = value - move2;
    pos3 = value - move3;
    pos4 = value - move4;
    pos5 = value - move5;
    pos6 = value - move6;
    pos7 = value - move7;
    pos8 = value - move8;
    pos9 = value - move9;
    pos10 = value - move10;

    pos5

    View post on imgur.com

    Beau McCombs replied 6 years, 1 month ago 2 Members · 4 Replies
  • 4 Replies
  • Andrei Popa

    July 25, 2020 at 7:51 am

    Try this.
    Change the 12 from the first row to how many frames you want the animation to take.
    It should move to the next text with each marker.


    dur = 12*thisComp.frameDuration;
    d1 = (thisComp.layer("TextBox 1").content("Rectangle 1").content("Rectangle Path 1").size[0]/2) ;
    d2 = (thisComp.layer("TextBox 2").position[0]) ;
    d3 = (thisComp.layer("TextBox 3").position[0]) ;
    d4 = (thisComp.layer("TextBox 4").position[0]) ;
    d5 = (thisComp.layer("TextBox 5").position[0]) ;
    d6 = (thisComp.layer("TextBox 6").position[0]) ;
    d7 = (thisComp.layer("TextBox 7").position[0]);
    d8 = (thisComp.layer("TextBox 8").position[0]);
    d9 = (thisComp.layer("TextBox 9").position[0]);
    d10 = (thisComp.layer("TextBox 10").position[0]);

    move1 = d1;
    move2 = d1 + d2;
    move3 = d1 + d3;
    move4 = d1 + d4;
    move5 = d1 + d5;
    move6 = d1 + d6;
    move7 = d1 + d7;
    move8 = d1 + d8;
    move9 = d1 + d9;
    move10 = d1 + d10;

    pos = [
    value - move1,
    value - move2,
    value - move3,
    value - move4,
    value - move5,
    value - move6,
    value - move7,
    value - move8,
    value - move9,
    value - move10,
    ];

    if (marker.numKeys > 0) {
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time) {
    n--;
    }
    }
    if (n == 0 || n >= pos.length){
    pos[0];
    }else{
    t = marker.key(n).time;
    ease(time,t,t+dur,pos[n-1],pos[n])
    }

    Andrei
    My Envato portfolio.

  • Beau McCombs

    July 26, 2020 at 8:21 pm

    Thank you so much for taking the time to work this out! I’m getting an error on line 43:

    “Property or method named ’n’ in Class ‘global’ is missing or does not exist. It may have been renamed, etc. etc.”

    Here’s that line:
    if (n == 0 || n >= pos.length)

    Let me know what you think.

    if (n == 0 || n >= pos.length)

  • Andrei Popa

    July 27, 2020 at 11:46 am

    I think you may have an error when no markers are present. This should not throw any error, even if no markers are there

    dur = 12*thisComp.frameDuration;
    d1 = (thisComp.layer("TextBox 1").content("Rectangle 1").content("Rectangle Path 1").size[0]/2) ;
    d2 = (thisComp.layer("TextBox 2").position[0]) ;
    d3 = (thisComp.layer("TextBox 3").position[0]) ;
    d4 = (thisComp.layer("TextBox 4").position[0]) ;
    d5 = (thisComp.layer("TextBox 5").position[0]) ;
    d6 = (thisComp.layer("TextBox 6").position[0]) ;
    d7 = (thisComp.layer("TextBox 7").position[0]);
    d8 = (thisComp.layer("TextBox 8").position[0]);
    d9 = (thisComp.layer("TextBox 9").position[0]);
    d10 = (thisComp.layer("TextBox 10").position[0]);

    move1 = d1;
    move2 = d1 + d2;
    move3 = d1 + d3;
    move4 = d1 + d4;
    move5 = d1 + d5;
    move6 = d1 + d6;
    move7 = d1 + d7;
    move8 = d1 + d8;
    move9 = d1 + d9;
    move10 = d1 + d10;

    pos = [
    value - move1,
    value - move2,
    value - move3,
    value - move4,
    value - move5,
    value - move6,
    value - move7,
    value - move8,
    value - move9,
    value - move10,
    ];

    if (marker.numKeys > 0) {
    n = marker.nearestKey(time).index;
    if (marker.key(n).time > time) {
    n--;
    }
    }else{
    n=0;
    }
    if (n == 0 || n >= pos.length){
    pos[0];
    }else{
    t = marker.key(n).time;
    ease(time,t,t+dur,pos[n-1],pos[n])
    }

    Andrei
    My Envato portfolio.

  • Beau McCombs

    July 27, 2020 at 4:18 pm

    Yep, you were right! I had markers on the comp, but not on the layer. That worked wonderfully. Thank you so much for this, I really appreciate it.

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