Skip to main content
Participant
November 12, 2025
Answered

Help with expression to move y position depending on condition

  • November 12, 2025
  • 1 reply
  • 71 views

Hello,

I am struggling to get this expression to work. I thought someone might be able to help me. I want a text layer to move y position depending on an if-else statement. If the text field is one or two line heights or not move to y1 or y2 position... Right now, this code works, but instead of moving the y it displays the y position with the text value. (example: some text1820) I am not sure what I am doing wrong.  Thanks!

 

var l = thisLayer

var tx = l.text.sourceText.value; 

var h = tx.split('\r');

 

var n = h.length; var y1 = transform.yPosition = [1920];

var y1 = transform.yPosition = [1920];

var y2 = transform.yPosition = [1820];

 

if (n > 1) {

[value + y2 ];

 } else {

[ value + y1 ];

}

Correct answer Dan Ebberts

It sounds like you might have applied your expression to the source text property instead of the layer's position property. I'm not sure exactly what you're after, but this position expression might be close:

n = text.sourceText.split("\r").length;
y = n == 1 ? 1820 : 1920;
[value[0],y]

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
November 12, 2025

It sounds like you might have applied your expression to the source text property instead of the layer's position property. I'm not sure exactly what you're after, but this position expression might be close:

n = text.sourceText.split("\r").length;
y = n == 1 ? 1820 : 1920;
[value[0],y]
Participant
November 12, 2025

Thanks for the reply. I need the info from the line height in the source text to affect the layer position. Your code does the same thing mine does, except it cuts off the text to the first character. value[0] returns the first character. I need it to keep the source text value, and move to either 1820 or 1920, depending on whether there is 1 or 2 lines in the source text. However, I think you're right, I am not applying the position to the layer, only the source text, which is why it's returning just the y numbers and not moving the layer. 

Dan Ebberts
Community Expert
Community Expert
November 12, 2025

Just to be clear, my expression should not be applied to source text, it's a position expression. Am I missing something?