Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Sourcetext ignore ( or create ) line breaks

  • Sourcetext ignore ( or create ) line breaks

  • Adam Greenberg

    September 14, 2021 at 2:03 pm

    I want a sourcetext expression to ignore a line break if there is one, and/or also have the control to add it’s own.

    I am creating a template that will have multiple composition size exports. Here are just 2 of them. example ( 1920 by 1080 ) and ( 1080 by 1920 )

    But I’d like one place to edit the text. So let’s say this is the text;

    ‘’ Shark Week The killers in Hawaiii ‘’

    If I expression source text this to both comps, This would fit easily as 1 line in the 1920 width composition.

    but the 1080 width comp, it would need to appear as 2 lines as follows

    ‘’ Shark Week

    The killers in Hawaiii ‘’

    But if I make a paragraph box it will appear like this ( which is not good ) ;

    ‘’ Shark Week The

    killers in Hawaiii ‘’

    The user would need to decide the appropriate place for the line break even though there won’t be a line break in the 1920 by 1080 composition most of the time

    Is there any possible work around ?

    Thanks

  • Andrei Popa

    September 14, 2021 at 3:06 pm

    Maybe use the 1080 comp text in the 1920 but replace newlines with spaces. Something like:
    text.sourceText.replace(/\r/g,” “)

  • Adam Greenberg

    September 14, 2021 at 6:54 pm

    That’s fantastic Andrei. Thanks so much.

    To get the opposite result, I wonder if it’s not possible.

    The best I can think of is a similar but opposite expression linked to a slider somehow. Like the slider would represent which space turns into a line break.

    Just a thought.

  • Chris Voelz

    September 15, 2021 at 7:18 pm

    You could use a slider that controls the character placement of \r code. Set a text animator to words and use the slider to position the carriage return.

    Or hard code the two variants into the text layer and use an if statement based on comp width to control which variation to display.

  • Adam Greenberg

    September 20, 2021 at 2:47 pm

    yes, thanks, I think it’s a good option. But I’m not fully sure how to write that out

  • Chris Voelz

    September 20, 2021 at 5:37 pm

    This would be an easier solution if you don’t need much variability.

    w1920 = "Shark Week The killers in Hawaii";

    w1080 = "Shark Week \rThe killers in Hawaii";

    if (thisComp.width == 1920){

    w1920;

    }else{

    w1080;

    }

  • Adam Greenberg

    September 20, 2021 at 7:01 pm

    well i never know what the text will be so the slider ( for the 1080 comps only ) could represent the spaces, and as i slide the slider up, it will change the line break, for example;

    title is – ONCE UPON A TIME IN AFTER EFFECTS

    SLIDER AT 0 WOULD BE –

    ONCE UPON A TIME IN AFTER EFFECTS

    SLIDER AT 1

    ONCE

    UPON A TIME IN AFTER EFFECTS

    SLIDER 6-

    ONCE UPON A TIME IN AFTER

    EFFECTS

  • Andrei Popa

    September 21, 2021 at 10:24 am

    If you want to put the line break via slider, you could use this:

    var s = text.sourceText;
    var f = " ";
    var r = "\r";
    var n = effect("Slider Control")("Slider").value;
    const replace_nth = function (s, f, r, n) {
    // From the given string s, replace f with r of nth occurrence
    return s.replace(RegExp("^(?:.*?" + f + "){" + n + "}"), x => x.replace(RegExp(f + "$"), r));
    };
    replace_nth(s,f,r,n);
  • Adam Greenberg

    September 21, 2021 at 12:14 pm

    yes exactly this.

    Thanks so much Andrei.

    I am sure this will prove useful for many people when they want to avoid retyping the same text which is be used across different composition width formats yet need that extra control.

    That’s just fantastic

Viewing 1 - 9 of 9 posts

Log in to reply.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy