Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions expression on layer 1 property — automatically access same property on layer 2?

  • expression on layer 1 property — automatically access same property on layer 2?

    Posted by Ross Klettke on August 10, 2012 at 8:03 pm

    Hi,
    A simplified example– Let’s say I have:
    2 layers– one named “leader” and one named “follower”

    I want an expression that I can apply to any property of the follower layer– and it’ll automatically grab the value of that same property from the leader layer (without me having to edit the expression to enter the specific property name). Kinda copying the animation on the leader layer to the follower layer.

    I’ve figured out one way to do it, but I hope there is a cleaner way.
    (this only works for X Position and Y Position)


    leaderStringVar = "thisComp.layer("leader")";
    propertyNameVar = thisProperty.name;

    if(propertyNameVar == "X Position")
    propertyNameVar = "xPosition";
    else if(propertyNameVar == "Y Position")
    propertyNameVar = "yPosition";

    eval(leaderStringVar + ".transform." + propertyNameVar + ";");

    Any ideas?
    Thanks!

    Ross Klettke replied 13 years, 9 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    August 10, 2012 at 9:12 pm

    That’s a tricky one (but very useful, I think). I’m not sure it works for everything, but it seems to work for everything I tested:


    leaderStringVar = 'thisComp.layer("leader")';
    p = thisProperty;
    str = ".value";

    while(!(p instanceof Layer)){
    str = '("' + p.name + '")' + str;
    p = p.propertyGroup(1);
    }
    str = leaderStringVar + str;
    eval(str)

    Dan

  • Ross Klettke

    August 10, 2012 at 9:37 pm

    Awesome– that’s a great solution (and I learned a bit about propertyGroup() too)
    Thanks Dan for this and, of course, everything you’ve done for the AfterEffects community

    –Ross

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