Skip to main content
cyBartek
Inspiring
August 11, 2024
Answered

How to create path from parented layers using fromComp expression?

  • August 11, 2024
  • 2 replies
  • 761 views

Hi,
I created a path based on the positions of two other layers using the fromComp expression (code below). It worked fine until I parented those source layers to null. Once they were parented the position of created shape shifted. 
I know it happens because the position is now related to null's position but I don't know how to fix it. 
Is there a way to write this code to include this related position? 

layNum = thisLayer.name.split("-")[1];
liEx = effect("link-extremes")("Slider");
l1 = thisComp.layer("Left-stripe-"+layNum);
l2 = thisComp.layer("Right-stripe-"+layNum);
p1 = thisLayer.fromComp(l1.transform.position);
p2 = thisLayer.fromComp(l2.transform.position);
createPath([(p1-[liEx,0]),(p2+[liEx,0])], [], [], false);

 



This topic has been closed for replies.
Correct answer cyBartek

Ok. I figured it out. I added the position of a parent layer to the path's points position.
But if there are some other ways to do it I will be happy if you share it. 🙂

New code:

layNum = thisLayer.name.split("-")[1];
liEx = effect("link-extremes")("Slider");
l1 = thisComp.layer("Left-stripe-"+layNum);
l2 = thisComp.layer("Right-stripe-"+layNum);
vPos = thisComp.layer("▣ Void 1").transform.position;
p1 = thisLayer.fromComp(l1.transform.position+vPos);
p2 = thisLayer.fromComp(l2.transform.position+vPos);
createPath([(p1-[liEx,0]),(p2+[liEx,0])], [], [], false);

2 replies

cyBartek
cyBartekAuthorCorrect answer
Inspiring
August 11, 2024

Ok. I figured it out. I added the position of a parent layer to the path's points position.
But if there are some other ways to do it I will be happy if you share it. 🙂

New code:

layNum = thisLayer.name.split("-")[1];
liEx = effect("link-extremes")("Slider");
l1 = thisComp.layer("Left-stripe-"+layNum);
l2 = thisComp.layer("Right-stripe-"+layNum);
vPos = thisComp.layer("▣ Void 1").transform.position;
p1 = thisLayer.fromComp(l1.transform.position+vPos);
p2 = thisLayer.fromComp(l2.transform.position+vPos);
createPath([(p1-[liEx,0]),(p2+[liEx,0])], [], [], false);

Legend
August 11, 2024

if vPos is for the vertical position you can use this:

layNum = name.split("-")[1];
liEx = effect("link-extremes")(1);
l1 = thisComp.layer("Left-stripe-" + layNum);
l2 = thisComp.layer("Right-stripe-" + layNum);
vPos = parent.transform.position;

p1 = fromWorld(l1.toWorld(l1.anchorPoint));
p2 = fromWorld(l2.toWorld(l2.anchorPoint));

yOffset = vPos[1] - transform.position[1];

createPath([(p1 - [liEx, -yOffset]), (p2 + [liEx, yOffset])], [], [], false);
cyBartek
cyBartekAuthor
Inspiring
August 12, 2024

No. vPos is my parented null layer (Void 1) position (both x and y). 
Nice trick with using the .parent method! 🙂
Thanks again for your help. 

Legend
August 11, 2024

Try this:

layNum = thisLayer.name.split("-")[1];
liEx = effect("link-extremes")("Slider");
l1 = thisComp.layer("Left-stripe-" + layNum);
l2 = thisComp.layer("Right-stripe-" + layNum);

p1_world = l1.toWorld(l1.anchorPoint);
p2_world = l2.toWorld(l2.anchorPoint);

p1 = thisLayer.fromWorld(p1_world);
p2 = thisLayer.fromWorld(p2_world);

createPath([(p1 - [liEx, 0]), (p2 + [liEx, 0])], [], [], false);
cyBartek
cyBartekAuthor
Inspiring
August 11, 2024

It works too. Thanks!