• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to modify scale of shape based on amount of characters

Community Beginner ,
Oct 23, 2022 Oct 23, 2022

Copy link to clipboard

Copied

The title says it all! I am trying to modify the scale of a shape based on the amount of characters on a text layer above it. Allowing it to stay wide enough for the characters to fit. I am looking for an expression that sets the scale of the current composition layer ONLY IF there are at least 4 characters. I would set the scale using the expression;

 

if(thisComp.layer("Control").effect("Channel Control")("Menu") == 1){ thisLayer.transform.scale = [SCALEx,SCALEy];

else {

     value;

}

 

SCALEx and y being replaced with their respective counterparts.

 

Any help is greatly appreciated!

TOPICS
Error or problem , Expressions

Views

201

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 24, 2022 Oct 24, 2022

While the guys are right about using sourceRectAtTime, you could use split to turn the string into an array and then count the length:

var txt = thisComp.layer("My Text").text.sourceText.split('');
var scaleX = 200;
var scaleY = 125;
if (txt.length < 4) {
	[scaleX,scaleY]
} else {
	value
}

 

Votes

Translate

Translate
Community Expert ,
Oct 23, 2022 Oct 23, 2022

Copy link to clipboard

Copied

An easier approach is to use sourceRectAtTime() to control the size and even the position of a shape layer. There are lots of tutorials on the subject.

 

You could drive layer scale, but Rectangle Size is much easier to control.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2022 Oct 23, 2022

Copy link to clipboard

Copied

As Rick already said, sourceRectAtTime() is the way to go. Basing such stuff on actual font metrics would be a nightmare, anyway, and AE doesn't offer any expression methods for doing it, so grabbing the bounding box dimensions of the rasterized content is as good as it gets. Minimum dimensions can be ensured by a simple if()else{} statement...

 

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

While the guys are right about using sourceRectAtTime, you could use split to turn the string into an array and then count the length:

var txt = thisComp.layer("My Text").text.sourceText.split('');
var scaleX = 200;
var scaleY = 125;
if (txt.length < 4) {
	[scaleX,scaleY]
} else {
	value
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

Is there a way to anchor the shape to the left? Meaning it will only expand to the right when more text is added?

 

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

You can change a shape layer group anchor point as you see fit. A simple parametric approach would be:

 

mSize=property("Rectangle").size;

 

X=value[0]-mSize[0]*0.5;

Y=value[1];

 

[X,Y]

 

Adjust the references as is adequate for your project.

 

Mylenium

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2022 Oct 24, 2022

Copy link to clipboard

Copied

LATEST

If you set a minimum width, then use sourceRectAtTime() to get the top and left height and width, you can compensate for the baseline shift in the text layer and paragraph justification. If you use the 2D Text box animation preset, you are 90% of the way to what you want. If the text is left justified, the box moves to the right. If the text is right justified, the box moves to the left. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines