Explanation:
- The expression checks the length of the text in the
sourceText
property. - If there’s one character (digit), it sets the x position to
760
, keeping the current y position (as indicated byvalue[1]
). - If there are two characters, it sets the x position to
700
, also keeping the current y position. - The
value
keyword represents the current position of the layer.
This should work for numbers in your text layer, adjusting the position accordingly based on the number of digits.
JavaScript
// Get the source text of the layer
var text = thisLayer.text.sourceText.value;
// Check if the text has one or two digits
if (text.length == 1) {
[760, value[1]]; // Set the x position to 760 if there is 1 number
} else if (text.length == 2) {
[700, value[1]]; // Set the x position to 700 if there are 2 numbers
} else {
value; // Default to the current position if the text doesn't match the condition
}
Leave a Reply