Skip to main content
Inspiring
Jun 17, 2024 4:00 PM UTC
Answered

Offset layers when resizing a composition

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 topic is closed to new replies. Start a new post to keep the conversation going.
HarchenkoCorrect answer
Inspiring
Jun 17, 2024 6:39 PM UTC

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;

1 reply

HarchenkoAuthorCorrect answer
Inspiring
Jun 17, 2024 6:39 PM UTC

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;
Translate