Skip to main content
Participant
March 22, 2023
Answered

Expression: Linking source text and font

  • March 22, 2023
  • 1 reply
  • 497 views

Hello there! 

 

I'm am fairly new to expressions and quite awful at it so far. Below in the screenshot, there are two text layers that should be linked in terms of style & font but not the text itself. Thank you in advance for sifting through this mess!

 

Objectives:

1) The text itself for both layers should be pulled from their respective layer name, hence my attempt with "thisLayer.name

2) The font/style of the lower layer titled "I'm about halfway out the door." should be linked to that of the one right above, which I attempted with the line "style.setFont(thisComp.layer("Tell me now, I gotta know.").text.sourceText.style.font);"

 

Attempts/Observation: When I added the second expression (highlighted in yellow) for either layer, the first was no longer being interpreted, meaning the text was no longer reflecting the layer name in the preview. When I isolate just the line linking the second layer's font to the first, it works. There was no error underlied, but I still suspect there's a syntax error. 

 

 

This topic has been closed for replies.
Correct answer Dan Ebberts

Try eliminating the thisLayer.name line and instead, append a .setText(thisLayer.name) to the second line. So, for example, the first expression would look like this:

style.setFont("Jattayu").setText(thisLayer.name);

 

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
March 22, 2023

Try eliminating the thisLayer.name line and instead, append a .setText(thisLayer.name) to the second line. So, for example, the first expression would look like this:

style.setFont("Jattayu").setText(thisLayer.name);

 

Participant
March 23, 2023

It worked!!! Thank you, Dan! I still wonder why the former was incorrect though. Could it be because multiple expression for the same property are not allowed? 

 

Dan Ebberts
Community Expert
Community Expert
March 23, 2023

That's basically it. The last result the expression calculates is the one that gets applied. So if you want to combine two or more expressions, you usually need to gather their results temporarily into variables and then somehow combine them in the last statement executed.