Skip to main content
iamsibtehassan
Known Participant
May 20, 2021
Question

Get layer Height when the Width hit a specific value

  • May 20, 2021
  • 3 replies
  • 417 views

Hey Everyone,

Just worndering if I could get the value of my layer's height when the layer width hits a specific value. I'm Animating layer size, and I want to Dynamically get the height when it gets to 50% (or any percentage or a fix value) of comp width. 
It may sound a bit wierd but It's kinda important.
TIA

This topic has been closed for replies.

3 replies

Mylenium
Legend
May 21, 2021

You would not necessarily base this on time at all. Something like this might suffice:

 

threshold = effect("EndLimit WIDTH")("Slider");
wid =Math.round(thisLayer.sourceRectAtTime(time).width);
hei=0;
snap=false;

while (time < thisComp.duration){
if (wid < threshold){
hei++;
break;
}else if (wid >= threshold){
snap = true;
}

if (! snap){
out=value[1];
}else{
out=hei;
}

 

Haven't checked this inside AE, but I hope you get the gist.

 

Mylenium

 

Mylenium
Legend
May 21, 2021

You may need to insert a break or continue in there somewhere, wrapped into a conditional. Hard to tell without seeing the code you actually used. Dan's audio trigger example might give you an idea, as it essentially covers your scenario, just based on audio:

 

http://www.motionscript.com/design-guide/audio-trigger.html

 

Mylenium

iamsibtehassan
Known Participant
May 21, 2021

Hey @Mylenium,

Things are a little clear now on my project. It turned out the Font Size of text layer is required at specific width threshold. I want the Text to resize till it fits the textbox. 

This is the Code I'm using, I modified the code you suggested and I think it's getting somewhere:

 

threshold = effect("EndLimit WIDTH")("Slider");
wid =Math.round(thisLayer.sourceRectAtTime(time).width);

above = false;

frame = Math.round(time / thisComp.frameDuration);
while (true){
t = frame * thisComp.frameDuration;
if (above){
if (wid < threshold){
frame++;
break;
}
}else if (wid >= threshold){
above = true;
}
if (frame == 0){
break;
}
frame--
}
if (! above){
t = 0;
}else{
t = time - frame * thisComp.frameDuration;
}

 

 


Thanks for your help 🙂

iamsibtehassan
Known Participant
May 21, 2021

All it does is assign the Comp Time in seconds to the slider value. What I want is that it assigns font size that fits the width threshold

Mylenium
Legend
May 20, 2021

For the super exact version working with any transforms and effects would have to run a while() loop that keeps on checking whether this threshold is met and then trigger a sampleImage() based on the time derived by the previous loop. Other than that of course you can always calculate this using a bunch of linear() functions, assuming there is nothing else going on. You need one function to correlate the input size or percentage value to the comp width, the other to compare the result of the first function to your scale animation and calculate the horizontal size.

 

Mylenium

iamsibtehassan
Known Participant
May 21, 2021

Thanks for the Reply. While Loop sounds promising. But when I try to put it together with my little knowledge of coding and references I found on internet, my After Effects keeps crashing. Maybe it's theinfinite loop.
Can you please help me with a simple example? Or is it too much to ask?