Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions export absolute scale and rotation after parenting

  • export absolute scale and rotation after parenting

    Posted by Marcel Ooms on September 4, 2013 at 2:37 pm

    Hey cow,

    I want to export data from one layer, which has been parented to multiple nulls for every shot. I need all the absolute data in one layer so I can export to .txt and copy the coordinates for an html project.

    for the absolute position I already found this on the forum:
    L = thisComp.layer(“layer”);
    L.toWorld(L.anchorPoint);

    This works great, but I was wondering if it is also possible to get absolute rotation and scale.

    Thanks in advance!
    marcel

    Rogier de Leeuw replied 5 years, 1 month ago 5 Members · 10 Replies
  • 10 Replies
  • Marcel Ooms

    September 5, 2013 at 1:57 pm

    I found what is weird about this: scale is in percentage, so it is a relative value. So what I’m asking is a absolute percentage….

    I’m starting to doubt if this is possible, although it seems like a pretty common thing to ask.

    Maybe a giant expression of 100*(percentage null1)*(percentage null2)…. etc is a solution? Or will I get weird values when taking percentages from percentages?

  • Dan Ebberts

    September 5, 2013 at 5:40 pm

    This should give you the world scale of a parented layer:

    s = scale[0];
    L = thisLayer;
    while (L.hasParent){
    s = s*L.parent.scale[0]/100;
    L = L.parent;
    }
    s

    And this should give you the rotation (unless the layers are 3D, which is a trickier problem):

    r = rotation;
    L = thisLayer;
    while (L.hasParent){
    r += L.parent.rotation;
    L = L.parent;
    }
    r

    Dan

  • Marcel Ooms

    September 6, 2013 at 4:48 pm

    I do not completely understand it, but it works! so thank a mega lot 🙂

  • Arne Münch

    May 15, 2014 at 12:05 pm

    Dan, I just love your amazing smart programming skills.
    these 7 lines are beautyfull, even for a bad coder like me..

  • Miha Zaletel

    September 9, 2015 at 9:28 pm

    Thank Dan, rely great code!

    How it counts the parents in while sentence?

    I just don’t understand how it jumps to next layer in chain and checks if has parent.
    For my case it works for 3layers long chain and then when it comes to fourth it breaks.
    The fourth parent layer is not in the line(index stack) with the first three.

    here is a sketch of layer stacking with index:

    lay1/index5 < lay2/inde6 < lay3/index7 < lay4/index15 < lay4/index1

    any idea?

    mz

  • Dan Ebberts

    September 9, 2015 at 9:48 pm

    It works for me with many layers, in any order. What are you doing with the result of the expression?

    Dan

  • Miha Zaletel

    September 10, 2015 at 2:59 pm

    It is complicated a bit.

    my purpose is to create ‘smart’ matte for HAND of a rigged character. Matte will allow to have hand behind the body and in front of the head. I have rigged character in main comp. In comp ‘hand matte’ I have solid, that fill area where both HANDS moves(solid cover hands in any position). On top of that solid I have HEAD with which I will control the shoving of hand in main comp(if hand is in front of head or not).

    So I’m trying to copy animation of the head in main comp to the ‘hand matte’ comp. I realize that your code works just fine, the breaker is the code for head position(I’ll paste it below). The code is beyond my
    knowledge. I changed if to while, but the problem stays the same(I thought that if sentence depends on layer index stack..).

    It is interesting that it breaks in 4ourth parent and not before.

    I know it’s wery confusing. If u have will I’ll be hapy to send you project. my mail is miha_zaletel@yahoo.com

    thank U,

    mz

    //from Felt Tips
    ctrl = comp("LOYZI_").layer("loy_GLAVA_newSCALE"); // head layer in main comp
    offsetP = thisLayer.toWorld(thisLayer.anchorPoint, 0) - ctrl.toWorld(ctrl.anchorPoint,0); //calculate absolute offset ?
    PWrld = ctrl.toWorld(ctrl.anchorPoint) + offsetP; //
    if(thisLayer.hasParent) thisLayer.parent.fromWorld(PWrld); // ctrl is parented not this layer, so how can expression work for first three parents chain?
    else PWrld;

  • Dan Ebberts

    September 10, 2015 at 4:13 pm

    I don’t completely understand what you’re trying to do, but if you want to follow the parenting hierarchy of the ctrl layer, you could do it like this:

    L = ctrl;
    while(L.hasParent){
    // do stuff
    L = L.parent;
    }

  • Miha Zaletel

    September 14, 2015 at 2:16 pm

    Dan, your method tracks parents perfect! And help me a lot, thank U.

    I use this method to track and than link position and rotation to a precomp. I just have problem that
    I have in main comp this layer linked to one of a parents in my chain. So I got double result.

    I calculate offset to eliminate double transformation when it is position change. But I cant set the proper offset for position of a layer when the animation is done by rotation(it works till it hits the parent layer in main comp ‘pants_ctrl’).

    Is it clear? I can recreate my comps setup.

    regards,

    mz

    on rotation I have:
    (I think that offset works fine, but not sure)

    ctrl=comp(“COMP”).layer(“HEAD”);
    mattP=comp(“COMP”).layer(“pants_ctrl”).transform.rotation;
    all= comp(“COMP”).layer(“position_ALL”).transform.rotation;

    r = ctrl.transform.rotation;
    L =ctrl;
    while (L.hasParent){
    r += L.parent.rotation ;
    L = L.parent;
    }
    r – mattP – all

    on position I have:

    ctrl=comp(“COMP”).layer(“HEAD”);
    mattP=comp(“COMP”).layer(“pants_ctrl”).transform.rotation;
    all= comp(“COMP”).layer(“position_ALL”).transform.rotation;

    off= ctrl.transform.position.valueAtTime(0) – ctrl.transform.position.value; // pure offset from sors position of my head layer
    offM= mattP.transform.position.valueAtTime(0) – mattP.transform.position.value; // offset wen parent 01 transforms position;
    offA= all.transform.position.valueAtTime(0) – all.transform.position.value; // offset wen parent 02 transforms position;

    P= ctrl.transform.position;
    L= ctrl;

    while(L.hasParent){
    if (L.parent == mattP && mattP.rotation !=0 )
    {

    P= ctrl.toWorld(ctrl.anchorPoint) – off; // if we deal with parent layer subtract offset ?
    L=L.parent;
    }
    else;

    P = ctrl.toWorld(ctrl.anchorPoint);
    L = L.parent;
    }

    P + offM + offA ;

  • Rogier de Leeuw

    April 1, 2021 at 3:44 pm

    L = thisLayer

    [100/length(L.toWorldVec([1,0,0])) , 100/length(L.toWorldVec([0,1,0])) , 100/length(L.toWorldVec([0,0,1]))]

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