Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Automated Title with expression via Essential Graphics

  • Automated Title with expression via Essential Graphics

    Posted by Matthias Schwarz on November 5, 2018 at 3:18 pm

    Hello my friends,

    I have a problem which is very complex in my point of view. I´m a rookie in writing expressions but I become better and try to learn as much as I can. I hope you can understand what I´m trying to explain because I´m no native speaker….Now to my case.
    I´m planning to build a title for Premiere CC, which should be provided there via Essential Graphics, but it´s made in After Effcts.
    The title does the following: You can write down the name of a Photo-Owner or a origin/source of videomaterial,

    e.g. “Photo:” …your text here…
    The “Photo” or “source”-text is not editable in the Premiere-title, it´s give by default.

    We use a company default font. What I did is to restrict the maximum letters to 40 lettes via “text.sourceText.substr(0,40);”-expression. It works fine. I managed to re-position the text in dependence to the length of the written text of the editor in Premiere CC, I did this via “sourceRectAtTime”, although I realized that it is only an approximation of the real text length. Is that right? The expression for that is:

    textweite = thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width;
    x = thisComp.width-textweite;
    y = position[1];
    [x,y];

    what I want to reach is something like this:

    x = thisComp.width-textweite/((100/transform.scale[0]))-effect(“Einstellungen für Schieberegler”)(“Schieberegler”);
    // comment: trying to find a formula to connect scale and x-Position, more letters=less than 100% scale

    if (thisComp.layer.position[0]<1436 ) [1436, y] else(); // comment: X Position nailed to the centre of the screen

    So far so good.
    But now I have to go further. And here starts the Problem. I need to restrict the Position of the text to the middle of
    the HD-Screen, and I realized that I can´t read out the amount of pixels given by the specific text, e.g an "W" has more pixels than an "i". But I need exact data to restrict it to the middle of the screen.
    An extra would be, to scale down to text automatically when the middle of the screen is reached, so that you can place even longer text, maybe more than the 40 letters, which I use now as a restriction for the moment.

    Now to my questions:
    How can I restrict the text to stop at the middle of the screen?
    Does "SourceRectatTime" give me the correct amount of pixels of the text(I tried some code an it seems not..)?
    How can I translate the length of the written text to the scale-parameter, so that it holds the position in the middle
    of the screen while it´s getting smaller(in dependance to the extra letters written down, e.g. 50 or more letters.

    I really hope you understand what I mean.

    I´m excited which ideas you have,

    yours, Matthias

    Matthias Schwarz replied 7 years, 6 months ago 2 Members · 3 Replies
  • 3 Replies
  • Matthias Schwarz

    November 5, 2018 at 4:55 pm

    Now I found the correct syntax to nail the text to the middle of the screen(it is 1343 pixels):

    textweite = thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width;
    x = thisComp.width-textweite;
    y = position[1];
    if (x<1343) {x=1343} else value;
    [x,y];

    So now: When the middle-position is reached, the written text runs out of screen at the right. At this point I need an idea how to scale down this text more and more with every extra-letter so that it doesn´t leave the screen.


    textweite = thisComp.layer("Filmausschnitt: ").sourceRectAtTime().width;
    x = thisComp.width-textweite;
    y = position[1];
    if (x&lt;1343) {x=1343} else value;
    [x,y];

  • Sam Catt

    November 6, 2018 at 12:00 pm

    This piece of code will make your text scale to the width of your comp : a small break down;

    var l = thisComp.width/thisLayer.sourceRectAtTime(time,true).width;

    calculates the width of your comp and divides it’s results by the width of your text. the sourceRectAtTime doesn’t change by the scale. The scale is simply a multiplier of the current size of your text. 100% = 100% of it’s size and 200% being double the original size.

    change *thisComp.width* to any numerical value to make your text adapt to that size.

    padding = clamp(effect(“Slider Control”)(“Slider”), 10, 100);

    add a slider to your layer and use this to add a padding boarder around the text, clamping simply stops you from going below a scale of 10.

    [ ( 100* ( (padding/100 )* l ) ) , ( 100* ( ( padding/100 )* l ) )]

    is two parts of your scale, both the X and Y : each part is the same

    it’s taking the 100% value of your text box, then it’s increasing the scale depending on how long the original text is. The longer the text the larger the scale, the shorter the text the larger.

    Though be warned small sentences will start pretty large…

    var l = thisComp.width/thisLayer.sourceRectAtTime(time,true).width;
    padding = clamp(effect("Slider Control")("Slider"), 10, 100);
    [ ( 100* ( (padding/100 )* l ) ) , ( 100* ( ( padding/100 )* l ) )]

  • Matthias Schwarz

    November 6, 2018 at 5:01 pm

    Sam, thank you so much for this Idea of changing the width of the text, I just tried it and it works fine. I´ll try this with further adjustments!
    For the moment I have found a solution that deals with some imperfections, but it works as I want it. I read out the length of the text and scale it down in two steps while reposition it approximately.
    For the Position I wrote this expression:

    textweite = thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width;
    x = thisComp.width-textweite;
    y = position[1];
    if ((transform.scale[0]<100) && (transform.scale[0]>69)) {[2000-textweite,y]} ;
    if (thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width>700) {[2080-textweite,y]} ;
    if (thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width>800) {[2100-textweite,y]} ;
    [x,y];

    For the Scale I wrote the following:

    if ((thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width>540) && (thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width<800)) {[80,80]} ;
    else if (thisComp.layer(“Filmausschnitt: “).sourceRectAtTime().width>800) {[65,65]};
    else value;

    Your code works fine for the scaling, but the issue with the fixed position still remains…

    Yours, Matthias

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