# Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Absolute Layer Possition [toWorld() expression]

• # Absolute Layer Possition [toWorld() expression]

4 Members · 7 Posts
• ### joshua faget

October 6, 2016 at 7:02 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];`

• ### Dan Ebberts

October 6, 2016 at 7:27 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

• ### joshua faget

October 7, 2016 at 11:15 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.

• ### Dan Ebberts

October 7, 2016 at 1:10 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

• ### Anthony Hairgrow

November 29, 2016 at 3:48 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”

• ### Herbert Muller

April 22, 2020 at 9:06 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.

• ### Anthony Hairgrow

April 22, 2020 at 7:18 pm

Man, this was so long ago that I can barely remember what I was working on at the time. I believe I was trying to do a Squash and Stretch rig. I think I got it to work, but I’d have to dig threw old files to find it. The solution I came up with has actually been implemented directly in After Effects now.

Viewing 1 - 7 of 7 posts