Site icon ProVideo Coalition

Free Function Friday itemLongestSide

Free Function Friday itemLongestSide 1

Ep. 04 itemLongestSide Free Function Friday

Welcome to Free Function Friday. This week we are building a function that will return which directional length of a comp or footage asset is longer. This can be handy when you are trying to determine if an asset is portrait or landscape in nature. So if you wanted to place a landscape asset into a portrait comp, or vice versa, you can determine which side you will need to adjust your math on to make it fit correctly.

For our function we will be customizing the return data by using an object array. Object arrays are a very common way to return multiple bits of data together. Objects are denoted by the surrounding open and closing curly braces like so…

{}

The contents of an Object array are listed out similar to a normal Array in that each item is separated by a comma, but also requires an attribute name surrounded by single quotes, then a colon, and then the attribute value like this two item object array sample. The grey text is what you would replace with your own name and values.

var myValues = {'attribute1Name': attribute1Value,

'attribute2Name': attribute2Value}

By using different attribute names for each piece of data we can retrieve each attribute just like when you access attributes for any other object. For a Composition Object you normally can access attributes for myComp.name, myComp.width, myComp.height, myComp.frameRate, myComp.pixelAspect, etc… this is because the object contains mulitiple values relating to that object. So to access our attribute2Value from the myValues variable, we would type…

myValues.attribute2Name;

For today’s function we will be creating our own attributes to return, one to return the resulting numerical value that is larger, and another to return a string representation of the longer side. In this case, we are using Width, Height, and Equal as our returned string options. You can certainly customize those strings to your liking, if you prefer a different naming.

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 4 itemLongestSide:

 

*The creation of OS folders is limited, so a 100% match is almost impossible in some scenarios. If you have more than one After Effects project folder with the same name inside the same parent folder, then this cannot be replicated on the OS side as it will try to save over the first folder name that already exists. So the code will ignore the dupllicate folder and just create one folder using that name.

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.

Exit mobile version