Copy link to clipboard
Copied
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);
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);
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);
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
It works too. Thanks!
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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);
Copy link to clipboard
Copied
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.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more