Forum Replies Created
-
Jarle Leirpoll
May 13, 2019 at 8:47 am in reply to: Expression error – can’t find out what’s wrong with my syntaxSOLVED!
I got help from Jonathan Beresford in a Facebook group. He suggested to use trim(), and that worked.
Here’s the final code. Hope it can help someone else.txt = comp("Subtitles 25 fps 1080x1920 With Line Break").layer("Source").text.sourceText.value;
nWords = Math.round(comp("Subtitles 25 fps 1080x1920 With Line Break").layer("Controls").effect("Word Split")("Slider"));
if (nWords > 0){
count = 0;
for (i = 0; i < txt.length; i++){
if (txt[i] == " "){
count++;
if (count == nWords) break;
}
}
if (count < nWords) txt
else txt.substr(i,txt.length).trimLeft()
}else{
i = Math.floor(txt.length-1);
n = -1;
while (i >= 0){
if (txt[i] == " "){
n = i;
break;
}
i--;
}
if (n < 0) ""
else txt.substr(n+1)
}Jarle Leirpoll
PremierePro.net -
Jarle Leirpoll
May 12, 2019 at 9:29 am in reply to: Expression error – can’t find out what’s wrong with my syntaxAlmost there! I’ve managed to split the text between words, and to adjust the split point with a slider. Works great, but the layer that grabs the second line starts with a space, not with a letter.
How can I strip away the space at the start?
Here’s the code for this layer.
txt = thisComp.layer("Source").text.sourceText.value;
nWords = Math.round(thisComp.layer("Controls").effect("Word Split")("Slider"));
if (nWords > 0){
count = 0;
for (i = 0; i < txt.length; i++){
if (txt[i] == " "){
count++;
if (count == nWords) break;
}
}
if (count < nWords) txt
else txt.substr(i,txt.length)
}else{
i = Math.floor(txt.length-1);
n = -1;
while (i >= 0){
if (txt[i] == " "){
n = i;
break;
}
i--;
j++;
}
if (n < 0) ""
else txt.substr(n+1)
}Jarle Leirpoll
PremierePro.net -
Jarle Leirpoll
May 10, 2019 at 7:22 pm in reply to: Expression error – can’t find out what’s wrong with my syntax -
Jarle Leirpoll
May 10, 2019 at 7:10 pm in reply to: Expression error – can’t find out what’s wrong with my syntaxPerfect! Works like a charm. I’m not surprised, though. ☺
Thanks Dan!Whenever you have the time, I’d like to understand why it’s now important to add “.value”
Jarle Leirpoll
PremierePro.net -
FYI: The expressions engine got an update in the 15.1.0 (CC 2018.1.0) version, where support for extents in Paragraph Text was added. In older versions, only shape layers have extents.
For a Paragraph Text layer, including extents will measure the bounding box, instead of only the bounds of the text’s visible pixels.
This change created problems for some users who had used “sourceRectAtTime(time, true)” for Paragraph Text in older versions, where the extra code didn’t do anything. In newer versions of Premiere Pro, the expressions suddenly behaved very differently, and they had to delete that extra code in their expressions.
Hope this helps.
// Previous expression
text_width = wordLayer.sourceRectAtTime(time, true).width;// How you need to write it now
text_width = wordLayer.sourceRectAtTime(time, false).width;or simply
text_width = wordLayer.sourceRectAtTime().width;
Jarle Leirpoll
PremierePro.net -
Jarle Leirpoll
October 21, 2017 at 7:59 pm in reply to: AE expression – split text in 2 seperate equal text linesThanks Dan – getting really close! Now the first layer does its thing correctly. Great!
The lower layer showed the same output as the first layer after I changed only the last line of code. So I guessed that this line also need to be changed.if (count < nWords) txt else txt.substr(0,i)
So I changed it to the following, and the split now kinda works.
if (count < nWords) txt else txt.substr(i,txt.length)
The result has two problems, though:
1. The second line always starts with a space
2. When the slider value is higher than the number of words, the lower layer shows the same as the upper layer/jarle
txt = thisComp.layer("Source").text.sourceText;
nWords = Math.round(thisComp.layer("Controls").effect("Text Split After (words)")("Slider"));
if (nWords > 0){
count = 0;
for (i = 0; i < txt.length; i++){
if (txt[i] == " "){
count++;
if (count == nWords) break;
}
}
if (count < nWords) txt else txt.substr(i,txt.length)
}else{
i = Math.floor((txt.length-1)/2);
j = (txt.length%2) ? i : i+1;
n = -1;
while (i >= 0 && j < txt.length){
if (txt[i] == " "){
n = i;
break;
}else if (txt[j] == " "){
n = j;
break;
}
i--;
j++;
}
if (n < 0) "" else txt.substr(n+1)
}Jarle Leirpoll
PremierePro.net -
Jarle Leirpoll
October 21, 2017 at 6:53 pm in reply to: AE expression – split text in 2 seperate equal text linesThanks Dan, that sounds like a good approach. But I’m not familiar enough with loops to understand what your loop does, and certainly not how to build a different one. ☺
I guess I could make two different text layers, and make Opacity expressions turn them on/off depending on the slider value – but I think that would make the comp a bit slower. There will be more layers doing the same thing, so it adds up.Jarle Leirpoll
PremierePro.net -
Jarle Leirpoll
October 21, 2017 at 2:49 pm in reply to: AE expression – split text in 2 seperate equal text linesDan, thank you for this code. I tried to use your code and expand it with a slider. The goal is to make the text auto-split like in your expression when the slider is set at 0. But if the slider is set at something else, the line break should come at that point, overriding the original behavior. Slider set to 2 should break the text after word 2, etc.
But my code doesn’t work properly.
txt = thisComp.layer("Source").text.sourceText;
k = Math.round(thisComp.layer("Controls").effect("Text Split After (words)")("Slider"));
i = Math.floor((txt.length-1)/2);
j = (txt.length%2) ? i : i+1;
n = -1;while (i >= 0 && j < txt.length){
if (txt[k] == " ") {
n = k;
break;
}else if (txt[i] == " "){
n = i;
break;
}else if (txt[j] == " "){
n = j;
break;
}
i--;
j++;
}
if (n < 0) txt else txt.substr(0,n)Jarle Leirpoll
PremierePro.net -
You could convert the audio level to keyframes (using the keyframe assistant) and then link to the Audio Amplitude Slider.
Jarle Leirpoll
PremierePro.net -
Jarle Leirpoll
October 20, 2017 at 5:16 pm in reply to: Right align text box + corresponding shape layerUnfortunately not. The usual method is to make two layers and set Opacity expressions. Or you could keep each line on separate layers (using split expression if you want only one text field in the mogrt) and position each layer (and the shape layer) relative to the width with expressions.
Jarle Leirpoll
PremierePro.net