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

Script to resize all layers to fit composition

New Here ,
Aug 03, 2021 Aug 03, 2021

I have a script to resize my compositions. But how would I make all the layers in the composition fit that composition size by using a script?

 

TOPICS
Scripting
4.8K
Translate
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

Community Expert , Aug 03, 2021 Aug 03, 2021

Getting the "visible bounds" can be very tricky.

There is the method AVLayer.sourceRectAtTime() which gives you those bounds in layer space and with

AVLayer.sourcePointToComp() you can convert those four corners to comp space.
However, this only takes layer transforms into account. If you have effects changing the content (like a corner pin or some warp effects) the actual visible layer could have very different visible bounds again.

Translate
LEGEND ,
Aug 03, 2021 Aug 03, 2021

There is any number of comp resizer scripts on AEScripts.com and of course fitting layers may be as trivial as invoking one of the Fit... options from the layer menu.

 

Mylenium

Translate
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
Community Expert ,
Aug 03, 2021 Aug 03, 2021

If you want to program it yourself, an easy solution would be to create a new null null in the center of the comp, parent all layers that have no parent to it and then scaling the null as needed.

Of course, that does not deal with different aspect ratios, yet. If you want to fit 16:9 content into a square comp, for example, the question where which part needs to be placed (and scaled) is a creative decision that cannot be automated easily.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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
New Here ,
Aug 03, 2021 Aug 03, 2021

Thank you. I think all I need is to get for each layer something similar to "visibleBounds" that are available in Illustrator (but I don't find in the AE scripting documentation). Because with that I can find the minX, maxX, minY and maxY for the layers and calculate the width and height and then set the comp size to that.

Do you know how to get the coordinates for a layer in AE?

 

    var theComp = app.project.activeItem;
    for (var i = 1; i <= theComp.numLayers; i++) {
        var curLayer = theComp.layer(i);
        $.writeln(curLayer) //here I would need to call a method on curLayer similar to visibleBounds in Illustrator to get the coordinates for this layer
    }
Translate
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
Community Expert ,
Aug 03, 2021 Aug 03, 2021
LATEST

Getting the "visible bounds" can be very tricky.

There is the method AVLayer.sourceRectAtTime() which gives you those bounds in layer space and with

AVLayer.sourcePointToComp() you can convert those four corners to comp space.
However, this only takes layer transforms into account. If you have effects changing the content (like a corner pin or some warp effects) the actual visible layer could have very different visible bounds again.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects
Translate
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
Community Expert ,
Aug 03, 2021 Aug 03, 2021

All of the resizing scripts that I have, including the Scale Comp script that comes with AE in the File/Scripts/Demo Pallet menu properly resize all layers in a comp. What exactly are you having problems with? I don't create very many compositions where every layer is the same size as the comp and I can't imagine wanting to do so. I do a fair amount of work in 4K and 6K comps that are destined for HD and 2K, and even social media frame sizes, but I seldom resize the comps. In a lot of cases, I'll render a mezzanine format Production Master/DI and then use the Media Encoder or Premiere Pro to take that 4K or 6K comp to different frame sizes for distribution. I do that because many of my effects and motion graphics comps can take well over a minute a frame to render. Resizing a video is always faster than rendering a comp again. 

Translate
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
New Here ,
Aug 03, 2021 Aug 03, 2021

Thanks for that insight. In my case I am exporting a lottie file from each composition and if there is extra space around the layers it results in extra space around the artwork in the lottie file. It looks like extra padding on the lottie file. When the composition has the same size as the layers, there is no padding visible when adding the lottie file to iOS at least.

Translate
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
Community Expert ,
Aug 03, 2021 Aug 03, 2021

Does it have to be a script?

 

Would using one of the Fit to Comp options work?

  • Layer > Transform > Fit to Comp, Fit to Comp Width, or Fit to Comp Height.

 

Any layer selected that the time you do this will be scaled to fit.

 

Translate
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