Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions get property of layer by index

  • get property of layer by index

    Posted by Andy Engelkemier on March 21, 2018 at 2:24 pm

    I’d like to use the same effect for a bunch of layers where I’m basically just linking only X or Y position of a parent layer. But I’d have to change the expression over and over.

    So I’d rather just have to keep the layers in order. So it’d be layered parent, child for X, child for Y, next parent, child for X, child for Y.

    So what I’m after is calling the position of the parent, but rather than using it’s name, it’s index. So i’d figure out my current child parent index and just subtract 1 (or 2 for the second child) so that they are pointing to the parent layer.

    But I can’t figure out how to change a layer property based on a specific index.

    Andy Engelkemier replied 4 years, 6 months ago 3 Members · 7 Replies
  • 7 Replies
  • Andrei Popa

    March 21, 2018 at 3:00 pm

    You mean like this?
    First child:
    thisComp.layer(index-1).transform.position
    Second child:
    thisComp.layer(index-2).transform.position

    Andrei
    My Envato portfolio.

  • Andy Engelkemier

    March 21, 2018 at 5:13 pm

    I think so, yes. thank you.
    All the examples I could find we calling just an index number, using the index to call on another property. So I couldn’t figure out how to order things.
    I suppose it’s always comp.layer.property.subproperty?

    I need just one example of the longest one possible, so I could see the order of things in order to properly call on things.

    Thanks

  • Dan Ebberts

    March 21, 2018 at 5:25 pm

    You could also use this to get the parent’s position:

    parent.transform.position

    this to get the grandparent’s position:

    parent.parent.transform.position

    etc.

    Dan

  • Andy Engelkemier

    March 21, 2018 at 5:56 pm

    That sounds like something I would use, but I’m not sure I understand.
    I don’t know what the “parent” part is indicating. Is that meaning that the layer is actually parented? Because putting position there wouldn’t make sense to me, unless maybe you’re after adding some math to it.

    I was after having a ground shadow and wall shadow follow my layer. But then I’d duplicate those layers, and replace them with a different object. But the expression doesn’t change to the newly duplicated layers, so I was looking to accomplish the same thing with index.

    So the ground shadow would be linked only to XZ, and the wall shadow would only be linking to XY.

    I didn’t like the effect anyway, but still like to know different ways of doing things. Especially when they are more efficient.

  • Dan Ebberts

    March 21, 2018 at 6:07 pm

    Ah, so the layers aren’t actually parented together. Sorry, I misunderstood.

    Dan

  • Andy Engelkemier

    March 21, 2018 at 6:25 pm

    Shoot, I thought you were about to teach me something that was going to blow my mind.

    I mean, always helpful of course. If you’re ever in Kalamazoo, I’ll buy some beers. Every time I’m stuck, I usually hit your site before even googling, and the answer is usually there. Most of which is over my scripting head, but still helpful.

  • Andy Engelkemier

    November 11, 2021 at 9:06 pm

    It’s pretty funny, I was searching how to do something Almost like this AGAIN, well because I haven’t had to in over 3 years and that’s how my memory works.

    But in case someone else ends up here searching for this as well, I figured I’d share what I came up with:

    On a shape layer, I created an ellipse path. I needed a circle on each of 22 layers, but I needed them to be one layer. Rather than positioning them all, then precomping I just did this on the position of one ellipse, then duplicated it. All the other objecst were directly above this layer. Just change the math based on where they are. From what I saw, you can’t specify a layer based on its index number, but you can do some math to the index of “this” (the layer with the expression) layer’s index to get what you need. It seems silly to me, but I’m still far from a programmer. Hopefully this will help someone, or maybe Me when I search for it again in 3 more years. lol

    GroupIndex = thisProperty.propertyGroup(1).propertyIndex;

    thisComp.layer(index-22+GroupIndex).transform.position;



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