Skip to main content
Inspiring
June 17, 2024
Answered

Offset layers when resizing a composition

  • June 17, 2024
  • 1 reply
  • 257 views

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 has been closed for replies.
Correct answer Harchenko

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
June 17, 2024

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;