Made a better version, but still need to look at the maximum height
var maxw = 1540;
var maxh = 800;
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 r1w = r1.sourceRectAtTime().width;
var r2w = r2.sourceRectAtTime().width;
var r3w = r3.sourceRectAtTime().width;
var totalw = Math.max(r1w,r2w,r3w);
var totalw = nr_rules == 2 ? Math.max(r1w,r2w) : totalw;
var totalw = nr_rules == 1 ? r1w : totalw;
var r1h = r1.sourceRectAtTime().height;
var r2h = r2.sourceRectAtTime().height;
var r3h = r3.sourceRectAtTime().height;
var totalh = r1h + r2h + r3h;
var totalh = nr_rules == 2 ? r1h + r2h : totalh;
var totalh = nr_rules == 1 ? r1h : totalh;
var sw = maxw / totalw * 100;
var sh = maxh / totalh * 100;
var tot = 100;
if (sw >= 140) tot = 140 else tot = sw;
[tot,tot]