Site icon ProVideo Coalition

Free Function Friday addCompMarker

Free Function Friday addCompMarker 1

Ep. 29 addCompMarker Free Function Friday


Free Function Friday addCompMarker

Welcome to episode 29 of the Free Function Friday series. addCompMarker is a function that will add a marker to your composition timeline. From a scripting perspective this is a something that natively does not exist in After Effects. We have access to layer markers, and can even set their comment, duration, chapter, cuePointName, eventCuePoint, URL, and frameTarget attributes. Composition markers however, we have no access to. So how do we build a function for something that has no native access? Well, we cheat, and by cheat I mean we venture into menu command id territory.

You’ve probably heard me warn about not doing this in the past, but today we are using app.executeCommand(). I try my best to avoid using this method due to it’s somewhat unstable nature, but sometimes you just have to go with what works if no other options exist. As far as I know there are no other ways to do this either. executeCommand() is a method that basically launches a menu command as if you clicked on it with your mouse cursor. In today’s function we need the “Add Marker” menu item to make this all work. Hopefully the app developers will not change it’s ID value, which is 2157 currently. Better yet, if they do change it, I hope it’s because they are adding a native option to ExtendScript, so we don’t have to find back doors like this.

Another feature that we need to add to this function to make sure it works properly, is layer selection retrieval. To add a comp marker successfully, no layers can be selected. Since we cannot guarantee that a user will always deselect layers at the right time, we need to do it for them. We also don’t want to be rude and will need to re-select the same layers after we add the comp marker. Doing this will create a fairly seamless experience for the user. One slight side effect of the deselect then reselect process is that the user may see a quick flash of the layers that were selected. It really depends on how large the timeline is and how many layers are selected at the time. You can’t even see it sometimes in small timelines. Regardless, I see that as a trivial blip for having the ability to get a comp marker created via scripting.

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 29 addCompMarker:

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 Moviola 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