2 Replies Latest reply on Sep 5, 2012 6:54 AM by Stephen Barrante

    Dynamically parent two layers together with expressions

    Stephen Barrante Level 1

      In AECS6, I have an Image Layer that is using the layer directly above as a Alpha Matte. I want both layers to scale at the same time, unless a certain condition is setup where I only want the matte to scale - leaving the image at original size. Normally I'd just make a new pair of layers and only scale that, but ALL my layers are dynamically linked to eachother for another more complex effect.


      I wrote a simple expression to get the current scale of the matte layer (index-1), and then calculate what this particular layer's scale should be. But the scales don't match up just right because we are dealing with percentages... not absolute values. However, if I simply parent the two layers together, it of course works.


      So, I either need to find a way to turn the parenting on/off with code, like if THIS, then ParentTo(index-1), or I need to write my scaling script correctly.


      Fwiw- here's that script:


      if (index != 15)) {

        // get the original and current scale value of the layer just above, and calculate an offset

                sOrig = thisComp.layer(index-1).transform.scale.valueAtTime(0)[0];

                sNow = thisComp.layer(index-1).transform.scale[0];

                sOffset = value[0] + (sNow - sOrig);


      } else {

      // this is layer index 15, don't do anything with it




      Appreciate the help!

        • 1. Re: Dynamically parent two layers together with expressions
          Mylenium Most Valuable Participant

          Not sure what you are getting at, but the actual value ranges do not really matter in an expression. It's more likely you are eitehr having an anchor point issue or your keyframes are simply not linear. in the latter case of course a simple subtraction would not give the correct result because values would be exponential/logarithmic/whatever. You'd have to use much more complex code then to accumulate all values over time such as the great Dan Ebberts explains on his website:




          Anyway, I suppose you could always use effects rather than native transforms to scale your matte while still leaving it parented. Y' know, there is a Transform effect... That would be much simpler and also avoid the expression evaluation bogging down your system...



          • 2. Re: Dynamically parent two layers together with expressions
            Stephen Barrante Level 1

            I apprecate your thoughts! I'll definitely check out the Transform Effect, which I always forget about. Is that generally faster than applying expressions directly to attributes?


            Simply put... parenting would solve my issue. But, I don't want my two layers parented to eachother permanently. This was something I was hoping I could script via some conditional statement.


            The alternative was to right an expression that would acheieve the same Scale matching as well as the parenting does. It wouldn't be a problem if these layers were scaled the same.. but I have one at like 18% and another at 55%... and unfrotunately, just adding 10% to each doesn't, of course, result in the same size increase. Well - let's just say I figured that out after the fact... duh.


            Thanks for the link - I actually perused his writeup a bit earlier.