PVC Exclusive | Industry Experts

Free Function Friday findCompByName

FFF Header

Welcome to Free Function Friday episode 11. This week we build a function to help us find a CompItem in the project by it’s name. Plenty of times there has been the need for simply searching for a comp by it’s name, instead of it’s ID (of which you would have to store in your code to have on hand to match later), or by knowing it’s project index number (which changes as you add and delete items). Now there is one hiccup with searching by name only, and that is your project can contain multiple files, folders, comps, etc… with the same name. This is because every single item in your project is assigned a unique ID number behind-the-scenes. So searching for a comp named “MyComp”, could actually match five different comps. For this function we take that into account and collect all matches into an Array of CompItems. From there you will have to narrow down the field to the specific comp you want by comparing other attributes, like width, height, pixel aspect, layer count, or something unique to what you are looking for. This is where the creative developer mindset comes into play. Lots of workarounds are needed when coding sometimes, so you have to be inventive in how to reach your end goal. So at the very least this function will get you all of the matching CompItem objects. If there is only one match, then job done. 🙂

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 11 findCompByName:


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.

Share Our Article

David Torno is a Visual Effects professional based in Los Angeles, California. His work over the years has included commercials, feature films, music videos, and multimedia projects. During his free time, David enjoys expanding his…

Leave a Reply

3 Comment threads
3 Thread replies
Most reacted comment
Hottest comment thread
3 Comment authors
Fabio ADavid Tornomatthieu wlazinski Recent comment authors
newest oldest most voted
Notify of
matthieu wlazinski
matthieu wlazinski

The idea seems to me the simplest is to add an id in the comments of each items

David Torno
David Torno

Adding the id to the comment section is doable, but many people like myself use that comment section for project notes, and it would get messy fast. If you wanted to read that comment via script. It would add an extra parsing step to the system. Plus ID’s are a native item attribute too, so placing them in the comments doesn’t seem very beneficial really other than for the user to see the number. The function could certainly be altered to return name and it’s id value, as an added layer of data to help determine the unique one a… Read more »

Fabio A
Fabio A

Hi David!! First of all, thanks for all!! incredible tutorials! So, let me ask you a quick question. I think this function is super useful, my plan is to find the comp by its name and then access the layers within. This has been easy for me doing it without a function, but I noticed that I am doing it so often within the code that makes sense consolidating into one function and call it every time I need to access layers of a specific comp. Is there anything I need to change to the function code in order to… Read more »