Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Parent to an object in another Comp

  • Parent to an object in another Comp

    Posted by Johan Nordström on July 20, 2011 at 10:07 am

    Hi!

    I’m so new att expressions, and i’m sure this has been up on the forum before.. but im having a hard time finding the answer.
    Here we go.

    I want a pre-composed shape layer to parent to a layer in the original composition. I want it to move and scale exactly like the original image but in the pre-comp.

    thnx.

    David Shukla replied 5 years, 10 months ago 5 Members · 6 Replies
  • 6 Replies
  • Greg Burrus

    July 20, 2011 at 2:57 pm

    If I understand you correctly you just want to know how you connect values between comps.

    If that is it you can drag one compositions timeline panel above the other by clicking and dragging the tab above until you see the blue shapes that tell you where you are placing it.

    Then you can just pick whip the values from one composition to the other.

    If you happen to have expression controllers you can lock the effects panel with the lock in the tab then open the other composition and pick whip the values.

    or you can just type the code below

    hope this helps

    greg

    comp("Comp name").layer("your layer name").value

    https://mogra.g2bproductions.com/ – Blog
    https://g2bproductions.com/ – Portfolio

  • Johan Nordström

    July 20, 2011 at 3:58 pm

    Yes!

    Thank you!
    I didnt think of that.. it was sooo easy…
    Thank you so much!

  • Pete Burges

    February 11, 2019 at 10:51 pm

    Here’s a head scratcher:

    Is it possible to parent a layer to a layer in another comp which is itself a child of another layer?

    I know how to ‘parent’ position by referencing the anchor point with this expression (below),

    but that doesn’t affect rotation or scale. Does anybody know a way of doing that…?

    Thanks,

    Pete

    target = thisComp.layer("target");
    target.toComp(target.anchorPoint);

  • Oleg Pirogov

    February 12, 2019 at 3:41 am

    In general, rotation and scale can be retrieved through observing the transformation of unit vector from child vector space to comp’s vector space.
    I.e.:

    child = thisComp.layer("Child Layer")

    //unit vector projection
    uVecProj = child.toComp([1,0])-child.toComp([0,0])

    //this gives Scale
    scale = 100*length(uVecProj);

    //this gives Rotation angle in [0, 360] degree range
    arcSin=Math.asin(length(cross(normalize(uVecProj), [1,0])))

    var angle = 0;
    switch (arcSin>=0){
    case true:
    angle = radiansToDegrees(Math.acos(dot(normalize(uVecProj), [1,0])));
    case false:
    angle = radiansToDegrees(2*Math.PI - Math.acos(dot(normalize(uVecProj), [1,0])));
    }

    angle;

    On daily basis though, I would rather get Scale by manually multiplying consequent Scale transformations of a given parent-child structure and Rotation – by adding Rotation transformations.

    Or just recreate the whole parent-child structure in another comp with nulls, directly linking nulls’ parameters to their prototypes’ parameters.

  • Pete Burges

    February 12, 2019 at 4:22 am

    Thank you so much for your detailed response, Oleg…!
    I have to admit a lot of that is over my head…I will have to go through it line by line several times until I understand it properly(I’m not really a script guy, I’m an animator who dabbles).
    In the end I made a workaround by using the anchor point to track position of the child, and then just taking the rotation and scaling from the parent object. Seems to work OK.

  • David Shukla

    July 2, 2020 at 1:46 pm

    Hi! I came here looking for solution to a similar problem! This code looks helpful but where should I put it?

    Usually, we put expression by alt-clicking on stopwatch next to property. Now that we want multiple properties to be parented, where should we write this code?

    Thanks!
    David

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