• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Offset layers when resizing a composition

Contributor ,
Jun 17, 2024 Jun 17, 2024

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;

 

TOPICS
Scripting

Views

67

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Jun 17, 2024 Jun 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;

Votes

Translate

Translate
Contributor ,
Jun 17, 2024 Jun 17, 2024

Copy link to clipboard

Copied

LATEST

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines