-
Autoscale layers to both height and width
Hi guys, I hope someone could help me with this one. I’m trying to scale 1, 2 or 3 text lines to a maximum height and maximum width.
The 3 lines are all in seperated comps beacause the have all sort of masks applied to them. There is a main slider control to show 1, 2 or 3 rules. I got the script working with the width values, but can’t seem to limit it to the maximum height. All 3 rules are in a precomps and the precomp is linked to a null who controls the scale. I think I made the script way to complicated and I’m a bit lost atm.Here’s the script so far
var maxw = 1540;
var maxh = 880;var nr_rules = effect(“nr_regels”)(“Slider”);
var r1 = comp(“txtFill s1r1”).layer(“txt-w1”);
var r2 = comp(“txtFill s1r2”).layer(“txt-w1”);
var r3 = comp(“txtFill s1r3”).layer(“txt-w1”);var r1width = r1.sourceRectAtTime(sourceTime(time), true).width;
var r2width = r2.sourceRectAtTime(sourceTime(time), true).width;
var r3width = r3.sourceRectAtTime(sourceTime(time), true).width;var r1height = r1.sourceRectAtTime(sourceTime(time), true).height;
var r2height = r2.sourceRectAtTime(sourceTime(time), true).height;
var r3height = r3.sourceRectAtTime(sourceTime(time), true).height;var h1 = maxh / r1height * 100;
var h2 = maxh / r2height * 100;
var h3 = maxh / r2height * 100;var w1 = maxw / r1width * 100;
var w2 = maxw / r2width * 100;
var w3 = maxw / r3width * 100;var totalh = h1 + h2 + h3;
var totalh = nr_rules == 2 ? h1 + h2 : totalh;
var totalh = nr_rules == 1 ? h1 : totalh;if (h1 > 120 && w1 > 120) { if (totalh > 600) { w1 = maxh / r1width * 100 } else { w1 = 120 }} else { w1 = maxw / r1width * 100 };
if (h2 > 120 && w2 > 120) { if (totalh > 600) { w2 = maxh / r2width * 100 } else { w2 = 120 }} else { w2 = maxw / r2width * 100 };
if (h3 > 120 && w2 > 120) { if (totalh > 600) { w3 = maxh / r3width * 100 } else { w3 = 120 }} else { w3 = maxw / r3width * 100 };var s = Math.min(w1,w2,w3);
var s = nr_rules == 2 ? Math.min(w1,w2) : s;
var s = nr_rules == 1 ? w1 : s;[s,s]
So the purpose is when you set the slider to 1 rule the total maximum width is 1540 and maximimum height is 400. And when you select 2 it looks at the widest of the two, and the same for when you set the slider to 3 rules. All rules together (either 1,2 or 3) can’t be higher then 880.
Thanks in advance!