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!
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
}
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.
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
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
}
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!
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
Copy link to clipboard
Copied
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.