Track nested child layer's position

Copy link to clipboard
Copied
Hi,
I have a Main Comp with a layer named 'Controller'.I have several 2d layers parented to this controller.
Now,i need to precompose two of them.let's say this precomposition of these two layers is named 'precomp 1'.
How can i parent these two layers in the 'precomp1' to the 'Controller' in the Main Comp again via Expression?
Dan,any ideas?
Copy link to clipboard
Copied
Hi!
The easy way is to have a copy of your 'Controller' in 'precomp 1'.
Your 2 layers will be parented to it.
On 'Controller' s position, put the following expression:
comp("Main Comp").layer("Controller").position;
The same for Scale, Rotation, AnchorPoint, if needed.
François

Copy link to clipboard
Copied
hi there,
You are right,that'll work but i'm wondering if there is a more elegant version without duplicating the controller layer.
I'd like to have the precomposed layers kind of parented to the layer “Controller” without being in the same comp.It's all in 2d space
Copy link to clipboard
Copied
Well, it depends on what you exactly need.
If it's only for position, then this should be enough :
comp("Main Comp").layer("myLayer's name").toComp(anchorPoint);
This will give you the absolute position of your layer.
If you need to get all the transformation Matrix, it becomes more difficult.
One solution is to apply a Corner Pin effect to your layer, put the layer in the Top Left corner of the composition,
and put the following expressions:
Top Left Corner:
comp("Main Comp").layer("myLayer's name").toComp([0,0]);
Top Right Corner:
comp("Main Comp").layer("myLayer's name").toComp([width,0]);
Bottom Left Corner:
comp("Main Comp").layer("myLayer's name").toComp([0,height]);
Bottom Right Corner:
comp("Main Comp").layer("myLayer's name").toComp([width,height]);
Otherwise, you have to get the absolute rotation, scale...
But if the parent is scaled, then you can have shearing that you cannot reproduce...
Hope it helps,
François

Copy link to clipboard
Copied
hi,
'If it's only for position, then this should be enough :
comp("Main Comp").layer("myLayer's name").toComp(anchorPoint);'
nope,it doesn't work correctly.The layer is offset.i would need to add an offset value in order to make it work correctly
Copy link to clipboard
Copied
Hi,
it should work if the anchorPoint has the same value and the comp have the same size.
Otherwise, please give me more details to see where issues come from...

Copy link to clipboard
Copied
Hello,
Yes, ahhh the anchor points are different.
Controller layer is a null 100x100Px Anchor Point = 0,0
Layers in the precomp are 1280x720 Anchor Point= 640,360
The offset is [640,360] or ?
Copy link to clipboard
Copied
Can you give me more precisions?
Did you take the option to duplicate the 'Controller'? With your layers attached?
Or do you try to get the absolute position of the layers directly?
Or did you apply the corner pin effect?
Don't be scared to give too much infos... Details can change everything.

Copy link to clipboard
Copied
hi,
jkhgsruigh wrote:
Or do you try to get the absolute position of the layers directly?
yes,correct.
Copy link to clipboard
Copied
So, you have:
-'precomp 1' with the same size than 'Main Comp'.
-inside 'precomp 1', you have 2 2D layers, lets say 'Layer 1' and 'Layer 2', with no parent.
-inside 'Main Comp', 'Layer 1' and 'Layer 2' are parented to 'Controller'.
In 'precomp 1', for 'Layer n':
anchorPoint: "comp("Main Comp").layer("Layer n").anchorPoint;"
position : "comp("Main Comp").layer("Layer n").toComp(anchorPoint);"
I've tested it on my side, it works... If it's not working on your side, you're still hiding something 😉
Cheers,
François

Copy link to clipboard
Copied
hi,
i'll test it and let you know,cheers

Copy link to clipboard
Copied
hi,
Sorry to disappoint you again but your code doesn't give me what i'm after.
Solution from Dan
p = comp("Main Comp").layer("Controller").transform.position;
value + p - p.valueAtTime(0
Solution from Felt
ctrl = comp("Main Comp").layer("Controller");
offsetP = thisLayer.toWorld(thisLayer.anchorPoint, 0) -ctrl.toWorld(ctrl.anchorPoint,0);
PWrld = ctrl.toWorld(ctrl.anchorPoint) + offsetP;
if(thisLayer.hasParent) thisLayer.parent.fromWorld(PWrld); else PWrld;
Copy link to clipboard
Copied
Hi,
no worry, as long as it works for you!
It seems I misunderstood what you exactly needed...
Cheers,
François
Copy link to clipboard
Copied
Hi François,
I have a question. There are 2 rectangular shapes on stage. I want to make each corner connected by lines using "beam effect". I put the Anchor point at one of the 4 corners. That corner works but I don't know how to make beam lines for the other 3 ....
In the Starting Point in the "beam01"
comp("MAIN").layer("Shape01").transform.position
I put comps called "target" inside "Shape01".
comp("MAIN").layer("Shape01").layer("target01").transform.position... syntax error
Can give me your advice that how to target the children's layers?
Thanks,
Kenji
Copy link to clipboard
Copied
Hi Kenji,
I'm not sure I really understand. Shape 01 is a comp, right? In this case your expression should look like this:
comp("MAIN").layer("Shape01").source.layer("target01").transform.position
And as you noticed, you can only access the position of the rectangle, not the positions of the corners... You'll have to calculate the corners positions from the position and the size of the rectangle.
If I misunderstood what you need, don't hesitate to send me a file, I'll take a lokk at it.
Cheers,
François
Copy link to clipboard
Copied
Hi François,
Thanks for your reply! And sorry for not explaining you what exactly I wanted to try. My friend gave me a script "toComp([0,0,])" then worked out well.
I really appreciate your help!
Cheers,
Kenji

