ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Modify sourceRectAtTime Expression to Ignore a Specific Character

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Quest Rogers
Modify sourceRectAtTime Expression to Ignore a Specific Character
on Oct 3, 2017 at 5:52:06 pm
Last Edited By Quest Rogers on Oct 4, 2017 at 2:02:11 pm

Hello.

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.

Thanks.

x=thisComp.layer("Title").sourceRectAtTime().width+18;
y=thisComp.layer("Title").sourceRectAtTime().height+12;
[x,y]


Return to posts index

Paul Connors
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Oct 5, 2017 at 4:54:57 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.


Return to posts index

Paul Connors
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Nov 13, 2017 at 2:36:02 pm

Howdy. Did you ever get an answer to this?


Return to posts index


Quest Rogers
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Nov 13, 2017 at 7:15:05 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.


Return to posts index

Dan Ebberts
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Nov 13, 2017 at 9:55:08 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;
etc....

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:

thisComp.layer("Text").text.sourceText.value.replace(/,/g,"")

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;


Dan



Return to posts index

Quest Rogers
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Nov 14, 2017 at 7:24:15 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?


Return to posts index


Dan Ebberts
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Nov 14, 2017 at 7:32:15 pm

Neither of my hacks actually removes the commas.

Dan



Return to posts index

Quest Rogers
Re: Modify sourceRectAtTime Expression to Ignore a Specific Character
on Nov 14, 2017 at 9:33:56 pm

Oh ok.

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

thisComp.layer("Title").text.sourceText.value.replace(/,/g,"")
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;
[w,h]


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];
[x/2,y/2]

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

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


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]