Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Maintaining even distance between layers, adjusting relative position

  • Maintaining even distance between layers, adjusting relative position

    Posted by Willie Frazier on February 24, 2015 at 9:36 pm

    Right – so I have 6 text layers that are spaced on Y=150. There may be a need to hide the bottom most layer and change the spacing of the remaining 5 to fill the compositional space. Is there a way via say a Slider Control and an additional expression to be able to adjust this? Say I needed the space between all of these to increase to Y=200. Can this be done elegantly without going to every single layer and placing a new value?

    Thanks
    – Wil

    Willie Frazier replied 11 years, 2 months ago 3 Members · 14 Replies
  • 14 Replies
  • Kevin Camp

    February 24, 2015 at 10:42 pm

    this would do what you are looking for:

    Line6 = thisComp.layer("Line 6");
    Yspacing1 = 150;
    Yspacing2 = 200;

    if (Line6.active == true) y = Yspacing1 else y = Yspacing2;

    thisComp.layer(index-1).position + [0,y]

    it just looks at line 6 to see if it is active or not and changes the y spacing value accordingly.

    — edit—-

    i should have added that you’ll need to paste that into the position property of lines 2, 3, 4 and 5.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Willie Frazier

    February 24, 2015 at 10:46 pm

    I see.. interesting idea… the mandate here is that they want flexibility for 4-6 lines, but it seems like this expression could be scaled out to accommodate that easily enough, I’ll give it a shot. Thanks!

  • Willie Frazier

    February 24, 2015 at 10:51 pm

    Actually, how would I scale that out to be a 4-6 line setup? And where would I apply this expression? With each row of text being its own layer, the Y value for each isn’t 150, rather its +150 from the previous group of text. Would I need to parent each group to the one above so that I have a consistent 150 value? This might make animating the text on tricky…

  • Kevin Camp

    February 25, 2015 at 12:18 am

    you could scale it out with else if statements. something like this would give you 4-6 lines (and you’d need to paste the expression into lines 2-6):

    Line4 = thisComp.layer("Line 4");
    Line5 = thisComp.layer("Line 5");
    Line6 = thisComp.layer("Line 6");

    SixLnSpacing = 150;
    FiveLnSpacing = 200;
    FourLnSpacing = 250;

    if (Line6.active == false && Line5.active == false) y = FourLnSpacing;
    else if (Line6.active == false && Line5.active == true) y = FiveLnSpacing;
    else y = SixLnSpacing;

    thisComp.layer(index-1).position + [0,y]

    the expression does look at the position of the layer above it.

    as for animating the text on, if you wanted to animate the position, I would try using a text animator for position rather than key framing the position properties, but it could be possible to work in the current position value of the layer into the equation.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Willie Frazier

    February 25, 2015 at 1:17 am

    Well, my goal here really is to make whatever intern they hand this over to’s life resemble hell as little as possible. Since what I need to toggle on or off consists of a row containing 3 text elements (a stat named flanked left and right with numbers) AND I have to animate them in a very specific way to match the established guidelines in the broadcast package (simple -Y animation with inverted alpha matte reveal), I opted for a route that is a little less ‘automatic’ but still fairly straightforward.

    I have in the scene 3 ‘control nulls’ for Color, Content, and Position

    The dividing lines between these stats are built with a single shape layer line and a repeater, and the ‘copies’ value has a slider control, so they can set it to 4, 5, 6.. whatever, and the Y position value of the repeater likewise has a slider control. Since the request here was for a 4-6 line variability option, I have the visible elements of each group linked to a group specific checkbox control for visibility. Each statistical group has it’s visible text parented to an ‘Ani’ null that will handle the -Y move. That null and the 3 matte objects that round out the group are subsequently parented to another null that allows the group to be globally repositioned.

    So, if one wanted to change the setup from 6 groups to 4, they would do the following:

    • Uncheck the checkbox control for visibility for groups 5 and 6
    • Set the dividing lines count to 4
    • Increase the Y to 200 (for example)
    • Go to groups 2-4 and set that ‘Repos’ value from 150 greater than the preceding group to 200 greater.

    In a perfect world, unchecking the visibility toggle control for a layer as in set 1 would make the rest of the steps happen automatically, but that seems more like the work of a script or plug-in, the authoring of which exceeds my current ability level to a prohibitive degree.

  • Kevin Camp

    February 25, 2015 at 8:46 pm

    ok… so you have 3 checkbox controls that control the opacity of 3 groups of layers.

    you could use those checkboxes to control the position property of the Ani nulls too (assuming the y animation doesn’t need to change, just be offset by a certain number of pixels). And the expression could be similar to the previous expression, but instead of looking at active layers, it would look at the check boxes.

    I’m going to assume that you have built the 6 line variation and that the y animation of the Ani nulls are set, and all you want to do is shift the Ani nulls down if you have fewer lines.

    Try something like this on the ‘Ani’ nulls’ position property (except the Ani nulll for line 1). Obviously change the Line5 and Line6 variables to point at your checkbox controls:

    Line5 = thisComp.layer("Control").effect("Checkbox Control 1").("Checkbox");
    Line6 = thisComp.layer("Control").effect("Checkbox Control 2").("Checkbox");

    SixLnSpacing = 0;
    FiveLnSpacing = 100;
    FourLnSpacing = 200;

    if (Line6 == false && Line5 == false) y = FourLnSpacing;
    else if (Line6 == false && Line5 == true) y = FiveLnSpacing;
    else y = SixLnSpacing;

    value + [0,y]

    it should shift the existing positions of the Ani nulls (and the layers grouped to them) but maintain the current animations.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Willie Frazier

    February 25, 2015 at 10:11 pm

    Great idea! I did try it however, and received an error:

    Is it possibly that I have the position values separated?

    **EDITT** I did try to combine the dimensions and reapply the expression, but the same error was returned.

    By the way, I really appreciate the time you’ve taken so far to help wit these 2 issues I’ve had.. it is very illuminating, and extremely helpful.

  • Kevin Camp

    February 25, 2015 at 10:42 pm

    i’m not sure why it says it has an error on line 1… but since the last line was expecting a 2-dimensional array (x,y), but you are separating dimensions, it should be changed to this:

    value + y

    try that and see if the error goes away. the rest of the syntax looks ok.

    Kevin Camp
    Art Director
    KCPQ, KZJO & KRCW

  • Willie Frazier

    February 25, 2015 at 11:12 pm

    Alas, no.. still returning the same error for line one… I don’t understand why it doesn’t work, it seems solid to me….

  • Dan Ebberts

    February 25, 2015 at 11:13 pm

    I think the error is because in lines 1 and 2, you have:

    .(“Checkbox”);

    instead of just:

    (“Checkbox”);

    Try taking the periods out.

    Dan

Page 1 of 2

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