Search code examples
javascriptadobeextendscriptafter-effects

Transforming compItem to different sizes using ExtendScript doesn't work as expected


I have a compItem in AfterEffect of ratio 9:16. I am writing a script to auto transform it to different size/ratios. For example to 16:9 and other etc.

If I duplicate the current compItem manually through AfterEffect and change the pixel size (from 1080:1920 to 1920:1080), it crops the video from top & bottom equally, which is fine.

But through the ExtendScript, if I duplicate & then update the width & height, it crops the video from only one side (bottom).

Following is the script I wrote. Any insights would be a great help, thanks.

var copies = {
    '4:5': [1080, 1350],
    '1:1': [1080, 1080],
    '16:9': [1920, 1080]
};

var currentComp = app.project.activeItem;

for (var i in copies) {
    var newCompItem = currentComp.duplicate();
    var width = copies[i][0];
    var height = copies[i][1];
    newCompItem.name = i;
    newCompItem.width = width;
    newCompItem.height = height;
};

Solution

  • It can be achieved by following steps:

    1. Create a new Null Object in current composition.
    2. Make it a parent for all layers in the composition.
    3. Write a script to change the size of composition as above.
    4. Center the Null Object.

    Centering the Null Object would auto center the layers as it's their parents.