Copy link to clipboard
Copied
Hi all. Can someone explain to me the logic of shifting layers when changing the size of the composition?
It always seemed to me that it was done like this, but I don’t get the same result as when changing the size of the composition through the interface
var comp = app.project.activeItem;
var w = comp.width;
var h = comp.height;
var nW = 1920;
var nH = 1080;
var x = nW / w;
var y = nH / h;
writeLn(x)
writeLn(y)
var layer = comp.layer(1);
var position = layer.position;
var anchor = layer.anchorPoint
position.setValue([position.value[0] * x, position.value[1] * y]);
comp.width = nW;
comp.height = nH;
This is a ready-made solution:
var comp = app.project.activeItem;
var w = comp.width;
var h = comp.height;
var nW = 1920;
var nH = 1080;
var layer = comp.layer(1);
var position = layer.position;
var x = position.value[0] /w;
var y = position.value[1] / h;
position.setValue([ w * x + nW / 2 - w/2, h * y + nH/2 - h/2]);
comp.width = nW;
comp.height = nH;
Copy link to clipboard
Copied
This is a ready-made solution:
var comp = app.project.activeItem;
var w = comp.width;
var h = comp.height;
var nW = 1920;
var nH = 1080;
var layer = comp.layer(1);
var position = layer.position;
var x = position.value[0] /w;
var y = position.value[1] / h;
position.setValue([ w * x + nW / 2 - w/2, h * y + nH/2 - h/2]);
comp.width = nW;
comp.height = nH;