Ep. 09 resizeComp Free Function Friday
Free Function Friday is upon us yet again, time for the weekend, and some free ExtendScript code learning. Today we build a function to resize a composition. You would think this is a simple straight forward task, but nope. You could use the native attributes
.height for a CompItem object and just set the size of the comp that way. Super simple and fast, but there is one issue, the layers in your comp may not look how you would expect them to afterwards. When you resize a composition in After Effects through it’s dialog window, the comp will resize from the center outwards. A fairly logical assumption when resizing. If you change the comp size via ExtendScript with the
.height attributes mentioned earlier, you’ll notice that it resizes the comp starting from the top left corner which produces a very different result. This has to do with screen coordinates for the viewer panel. If you reveal the ruler guides in the comp viewer you’ll see that the top left corner is a [0,0] coordinate and the bottom right corner will be whatever size your composition is, like [1920, 1080] for example.
Adobe was nice enough to do the math for you and automatically default to resizing from the center of the comp and not the true [0,0] point, but in ExtendScript it is up to us to do that math. For this function we are doing some simple offset math and building it to resize from the center of the composition by default, but you are certainly welcome to figure out the alternate offset math required to use the other corners of a comp as an option.
If you haven’t done so already there is a Free Function Friday introduction video located here that has some important information pointing to a few resources that will come in handy when scripting for After Effects.
Episode 9 resizeComp:
Legal note: The Adobe ExtendScript code talked about in this article and accompanying embedded video(s), and/or graphic images are not guaranteed to be compatible with every version of After Effects. David Torno, ProVideo Coalition, and Diversified will not be held liable for any misuse or incorrect use of the provided ExtendScript code. Use at your own risk.
All of the code I provide in this series, has been created and tested in After Effects CC 2014. Unless otherwise specified in the episode, the code should be compatible with After Effects CS6 through CC 2015. I’ve done my best to avoid depreciated code (code that Adobe removed at some point), and made these functions as compatible as possible. There will however be the occasional piece of code that is brand new as of a certain version of After Effects and therefore will not be backwards compatible from that version. I will mention these if that is the case.
With that said, all the code I provide in this series is open source and free to use in your scripts. I highly encourage you to expand and improve upon the code I provide and start making your own custom functions as well, but please do not repost the code I show in this series as is and claim it as your own. If you use any of the code provided in this series please give credit where credit is due. This series is meant to provide, what I feel is useful code, as well as to hopefully further explain ExtendScript and it’s quirks. While the functions we build throughout this series can perform a task all on their own, they are not meant to be a solo script. How you combine them together and expand upon them is when you will gain the most from these functions.