Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Forums Adobe After Effects Expressions Modify sourceRectAtTime Expression to Ignore a Specific Character

  • Modify sourceRectAtTime Expression to Ignore a Specific Character

  • Quest Rogers

    October 3, 2017 at 5:52 pm


    I’m wondering if someone can help me figure if it’s possible to modify the expression below to ignore a specific character. This expression is applied to a rectangle’s path size so that when text is typed a box increasing the visibility of the text is created behind it to the specific length of the line of text. When a comma is typed the box extends lower than I’d like and makes the text look as if it’s not perfectly centered in the box. Basically I want the expression to resize to the length of the text without factoring any commas.

    If anyone has any ideas I would appreciate any help.



  • Paul Connors

    October 5, 2017 at 4:54 pm

    This is a GREAT question. I have this exact issue from time to time and have just settled with it looking out of sorts. I would love to know the answer.

  • Paul Connors

    November 13, 2017 at 2:36 pm

    Howdy. Did you ever get an answer to this?

  • Quest Rogers

    November 13, 2017 at 7:15 pm

    Sadly, no. I knew it was a bit of a long shot and that no one would likely reply. I searched pretty vigorously for an automated solution to this and just couldn’t find one.

  • Dan Ebberts

    November 13, 2017 at 9:55 pm

    There are a couple of hacks you can try.

    Put an expression like this in your text layer’s Source Text property:

    if (time < 0) value.replace(/,/g,””) else value

    That will remove the commas at times less than zero. Then in your shape expression, you can get the sourceRect() at a negative time to get the height you want and at the current time to get the width:

    L = thisComp.layer(“Text”);
    h = L.sourceRectAtTime(-1,false).height;
    w = L.sourceRectAtTime(time,false).width;

    An alternative would be to have a hidden text layer with an expression that gets its text from the main text layer and removes the commas:


    Then your shape expression would again use two soureRect() references:

    h = thisComp.layer(“Text Copy”).sourceRectAtTime(time,false).height;
    w = thisComp.layer(“Text”).sourceRectAtTime(time,false).width;


  • Quest Rogers

    November 14, 2017 at 7:24 pm

    Hi Dan!

    This is helpful. I’ll try this out in the next couple of days.

    The only issue is that I don’t want the commas removed. My job has decided to use commas for certain punctuation in lower thirds. I’m trying to see if there’s a way for the expression on the shape to parse the source text for commas and ignore them. This would keep the text layer looking centered in the shape instead of the shape getting larger at the bottom to accommodate the comma descending below everything. What do you think? Is this possible?

  • Dan Ebberts

    November 14, 2017 at 7:32 pm

    Neither of my hacks actually removes the commas.


  • Quest Rogers

    November 14, 2017 at 9:33 pm

    Oh ok.

    I tried the alternative method you mentioned that seems to work well for me.

    This was applied to the source text of the duplicate text layer.

    h = thisComp.layer("Title Copy").sourceRectAtTime(time,false).height+13;
    w = thisComp.layer("Title").sourceRectAtTime(time,false).width+17;

    This was applied to the Size of the Rectangle Path Shape layer.

    x=content("Rectangle 1").content("Rectangle Path 1").size[0];
    y=content("Rectangle 1").content("Rectangle Path 1").size[1];

    And this was applied to the Position of the Rectangle Path Shape layer.

    Many thanks for your help with this Dan! Much appreciated.

  • Hans Terlouw

    July 17, 2019 at 12:09 pm

    This works perfect. I only want to add some more punctuation that needs to be excluded in the duplicate text layer. These are the following


    What would the expression be for the source text in the duplicate text layer?

  • Quest Rogers

    July 17, 2019 at 12:26 pm

    Like this. You need to separate what you want excluded with |\ and then the character.


Viewing 1 - 10 of 11 posts

Log in to reply.

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