Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to create path from parented layers using fromComp expression?

Explorer ,
Aug 11, 2024 Aug 11, 2024

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);

cyBartek_0-1723380754825.png

 



TOPICS
Error or problem , Expressions , How to
814
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Advocate , Aug 11, 2024 Aug 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);
Translate
Explorer , Aug 11, 2024 Aug 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);

...
Translate
Advocate ,
Aug 11, 2024 Aug 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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2024 Aug 11, 2024

It works too. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 11, 2024 Aug 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);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 11, 2024 Aug 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);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 12, 2024 Aug 12, 2024
LATEST

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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines