ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Absolute Layer Possition [toWorld() expression]

FAQ   •   VIEW ALL
 Absolute Layer Possition [toWorld() expression] on Oct 6, 2016 at 7:02:09 pm

Hello,

Im trying to calculate a layer position relative to the world. The reason being is that I want to calculate the distance between two layers and not get interference when one of those layers gets parented.

My Expression seems to work, BUT ... it seems that the world position is calculated from the top left corner. I've solved that with adding the X and Y from the layers anchor point, but it fails when the layer gets rotated.

To put it in other words. If I have a Layer with position values [960,540], after I parent it I want those values to remain the same, so my distance calculation remains accurate.

Any solutions?

Thank you very much.

```Layer = [whateverlayer]; A = Layer.toWorld(anchorPoint); X= A[0] + Layer.anchorPoint[0]; Y= A[1] + Layer.anchorPoint[1]; AbsPos = [X,Y];```

 Re: Absolute Layer Possition [toWorld() expression]on Oct 6, 2016 at 7:27:38 pm

Depending on what type of layer you're dealing with, this might work:

L = thisComp.layer("Null 1");
L.toWorld([L.width,L.height]/2)

Dan

 Re: Absolute Layer Possition [toWorld() expression]on Oct 7, 2016 at 11:15:50 am

Hello Dan,

Your solution works really well, but when the layer is a shape layer it doesn't work unfortunately. For some bizarre reason anchor point coordinates for a solid layer and a shape layer are different, when they are in the same spot.

 Re: Absolute Layer Possition [toWorld() expression]on Oct 7, 2016 at 1:10:41 pm

Shape layers are trickier. Try this:

L = thisComp.layer("Shape Layer 1");
r = L.sourceRectAtTime(time,false);
L.toWorld([r.left + r.width/2,r.top + r.height/2])

Dan

 Re: Absolute Layer Possition [toWorld() expression]on Nov 29, 2016 at 3:48:42 pm

Hi Dan,

I wanted to know how I could convert the local coordinates of a nested Shape Group to it's absolute World(Comp) position?

I'm developing a rig using nested Shape Groups within a single Shape Layer and wanted to know how I could obtain the Global position of a nested Shape Group. I'm trying to use the toWorld or toComp functions but those methods don't seem to work within Shape Layer contents. I keep getting errors.

As an example, lets say I have a Shape Layer called Controls. Within the shape layer, I have 2 Shape Groups, Group A and Group B. Within Group A, I have 2 other groups, Group A1 and Group A2. The position values of Group A1 and A2 are relative to Group A. Essentially, if I move Group A into position, Group A1 and A2 will follow but I still have independent control over the two nested groups. I'd like to convert the local value of the nest groups to either a World position or Comp position.

If I can obtain this number then I can link anything to the individual Shape Groups regardless of how it's parented/nested.

I've read previous forum posts where you've mentioned something like:

L = thisComp.layer("Null 1");
p = L.toComp(L.anchorPoint);
fromComp(p)

But this structure doesn't seem to work with Shape Layer groups.

In the first line I can't point directly to the Shape Layer Group Name. AE won't let me pick whip it. I have to explicitly point to the Position property of the Nest Group. Which works, but that's not the value I want.

Once I point to the Position property of the Nested Shape Group, then the second line will throw an error stating that "l.toComp is undefined"

 Re: Absolute Layer Possition [toWorld() expression]on Apr 22, 2020 at 9:06:28 am

Long shot here.

Did you ever solve this Problem?
I got something similar, where i want to parent the anchorpoint and position of a shape group to a Null Layer.