Skip to main content
Inspiring
February 10, 2024
Answered

Expression to target child layer in pre.comp

  • February 10, 2024
  • 1 reply
  • 285 views

I have a comp called "conversation" that has a pre-comp called "caption". The caption pre-comp contains a text layer ("caption-text") and a shape layer bg ("caption-bg") that acts as a speech bubble for the text and resizes depending on the text layer size.

 

I want to be able to access the the dimensions of "caption-bg" from the "conversation" comp, its parent. Is there an expression to look inside the contents of a pre-comp and access its layers? Maybe something like this in the "conversation" comp?

 

captionLength = layer("caption').subLayer("caption-bg").sourceRectAtTime().length

This topic has been closed for replies.
Correct answer Rick Gerard

Try this:

 

ref = comp("caption").layer("caption text");
box = ref.sourceRectAtTime();
boxSize = [box.width, box.height];

 

That will give you the width and height of the box. You can use the expression to set the size of a shape layer rectangle.

1 reply

Rick GerardCommunity ExpertCorrect answer
Community Expert
February 10, 2024

Try this:

 

ref = comp("caption").layer("caption text");
box = ref.sourceRectAtTime();
boxSize = [box.width, box.height];

 

That will give you the width and height of the box. You can use the expression to set the size of a shape layer rectangle.

AmozzaAuthor
Inspiring
February 12, 2024

Thanks Rick. This works great!

 

I also found another way to access the layers of the pre-comp using "source". For example:

 

textBG= thisLayer.source.layer("background").;