Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity › Forums › Adobe After Effects Expressions › SetFont and get different line width in same text box

  • SetFont and get different line width in same text box

    Posted by Anoki Acharya on December 30, 2020 at 9:45 pm

    This script from this post works really well to get the width of different lines in the same text box.

    if (time < 0){
    s = value.split("\r");
    txt = ""
    for (i = 0; i < s.length; i++){
    if (time > -10*(i+1)){
    txt = s[i];
    break;
    }
    }
    txt;
    }else
    value

    I am trying to set the font through the menu dropdown and get the width at the same time. This is what I tried but only one function works. Is there a way to combine both functions or is it impossible to have two different functions applied for sourceText?

    (New to expressions. Don’t know what is possible or not possible yet).

    //This changes font

    var dropDownFontMenuIndex = thisComp.layer("settings").effect("Font Menu Control")("Menu").value;

    switch ( dropDownFontMenuIndex ){

    case 1:

    style.setFont("Rockwell-Bold");

    break;

    case 2:

    style.setFont("Antonio-Bold");

    break;

    default:

    style.setFont("Rockwell-Bold");

    };

    //This returns value

    if (time < 0){

    s = value.split("\r");

    txt = ""

    for (i = 0; i < s.length; i++){

    if (time > -10*(i+1)){

    txt = s[i];

    break;

    }

    }

    txt;

    }else{

    value

    }

    Anoki Acharya replied 5 years, 9 months ago 2 Members · 3 Replies
  • 3 Replies
  • Filip Vandueren

    December 30, 2020 at 9:51 pm

    Something along these lines:

    if (time < 0){

    s = value.split("\r");

    txt = ""

    for (i = 0; i < s.length; i++){

    if (time > -10*(i+1)){

    txt = s[i];

    break;

    }

    }

    } else {

    txt = value

    }

    //This changes font

    var dropDownFontMenuIndex = thisComp.layer("settings").effect("Font Menu Control")("Menu").value;

    switch ( dropDownFontMenuIndex ){

    case 1:

    style.setFont("Rockwell-Bold");

    break;

    case 2:

    style.setFont("Antonio-Bold");

    break;

    default:

    style.setFont("Rockwell-Bold");

    };

    style.setText(txt);

    style;

  • Anoki Acharya

    December 30, 2020 at 10:27 pm

    That didn’t work but that gave me another idea. I will see if that works.

  • Anoki Acharya

    December 30, 2020 at 10:35 pm

    Added setFont and setText together and it works now. Thank you Filip!

    I have been at this for few days now.

    var txt = ""

    var dropDownFontMenuIndex = thisComp.layer("settings").effect("Font Menu Control")("Menu").value;

    if (time < 0){

    s = value.split("\r");

    for (i = 0; i < s.length; i++){

    if (time > -10*(i+1)){

    txt = s[i];

    break;

    }

    }

    }else{

    txt = value

    }

    switch ( dropDownFontMenuIndex ){

    case 1:

    style.setFont("Rockwell-Bold").setText(txt);

    break;

    case 2:

    style.setFont("Antonio-Bold").setText(txt);

    break;

    default:

    style.setFont("Rockwell-Bold").setText(txt);

    };

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