Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Keeping linked scale positive

  • Keeping linked scale positive

    Posted by Ben Robinson on August 8, 2013 at 12:24 pm

    Hi,

    I have a large stack of comps / layers whose scale parameters are linked to that of another layer in another comp, relative to their layer order / index.

    My current expression:

    comp(“Comp Name”).layer(“2nd Comp Name”).transform.scale-index

    The link works fine, of course-but, once the scale of the linked layer goes below half the number of indexed layers the scale returns a negative value. How can I return all negative values as 0? Or, better yet, is it possible to incrementally scale down such that only the last indexed layer reaches 0 when the linked layer does? Let’s assume there are 100 indexed layers. Hopefully that makes sense.

    I’ve looked at the Math.abs and Math.max operators but can’t quite work out how to implement them here.

    Thanks in advance.

    Ben Robinson replied 12 years, 9 months ago 2 Members · 7 Replies
  • 7 Replies
  • Xavier Gomez

    August 11, 2013 at 11:12 pm

    To get only positive values, you can do:
    x = (your expression);
    (x>0) ? x : 0; // equivalent to Math.max(x,0)

    For the other part, one way is to name your first layer “LEADER”, the last in the stack: “TAIL”, add 2 nulls, one called “Lead ctrls” and the other “Tail ctrls”, then paste this expression to every item’s scale in the stack

    leader = thisComp.layer(“LEADER”); leadctrls = thisComp.layer(“Lead ctrls”);
    tail = thisComp.layer(“TAIL”); tailctrls = thisComp.layer(“Tail ctrls”);
    linear(index, leader.index, tail.index, leadctrls.scale, tailctrls.scale);

    Then adjust the 2 nulls scales. It works the same way with other transform properties.

    Xavier.

  • Ben Robinson

    August 14, 2013 at 7:21 am

    Thanks very much for your help / reply. Haven’t had a chance to plug in your expressions yet–will let you know when I do.

    Thanks again.

  • Ben Robinson

    August 14, 2013 at 11:35 am

    Hi,

    Applying the expression as you’ve suggested…

    x=comp(“Comp Name”).layer(“Layer Name”).transform.scale-index;
    (x>0) ? x : 0

    …returns the following error:

    Expression result must be of dimension 2, not 1. Am I missing something?

    Also, I’ve just noticed that even the straightforward linking expression

    comp(“Comp Name”).layer(“Layer Name”).transform.scale-index

    is only affecting the width value; i.e. the index value is only subtracted from the width, not width and height. Why might that be?

  • Xavier Gomez

    August 14, 2013 at 9:44 pm

    I suppose you havent copied your expression properly in your first post and apparently you repeated it in your project.

    Scale is a 2D (or 3D) array, index is a number. So your original expression would have been
    comp("Comp Name").layer("Layer Name").transform.scale-index*something where ‘something’ is something only you can know what it was, but for sure an array of numbers. Probably [1,1].

    Xavier

  • Ben Robinson

    August 15, 2013 at 1:29 pm

    Hi Xavier,

    I see what you mean about the array. It was my impression that an operation on an array automatically affect all elements of the array, unless otherwise separated. Obviously not.

    I’m still confused about the only positive value expression. i think I did enter my original expression incorrectly in the first post, where I had, “…layer(“2nd Comp Name”)…” rather than, “…layer(“Layer Name”)…” So should my expression look like this:

    x=comp(“Comp Name”).layer(“Layer Name”).transform.scale-index*[1,1]
    (x>0) ? x : 0;

    Other than including the array multiplier, that is what I input and got the previously mentioned error.

    Thanks for your help here.

    Ben

  • Xavier Gomez

    August 15, 2013 at 3:02 pm

    hmm i’m really sorry. I was mostly answering the second question and didnt pay enough attention to the first one. This one is hopefully working better.

    s=comp(“Comp Name”).layer(“Layer Name”).transform.scale-index*[1,1];
    [Math.max(s[0],0), Math.max(s[1],0)];

    Xavier.

  • Ben Robinson

    August 15, 2013 at 4:45 pm

    That works a treat now.

    Thanks Xavier.

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