After effects: undocumented menu execution.

This has been around for a while but it took some serious digging on my part today to find again, figured a repost might be in order.

After Effects has two undocumented commands that you can use to work around AE’s arcane and often frustrating limitations:


function executeMenuCommand( name )
{
command = app.findMenuCommandId( name );
app.executeCommand( command );
}

The drawback of this of course is that this executes independently of the scripting workflow. In my case I needed to duplicate source footage items in the project window and alter footage interpretation (specifically, framerate). I was relatively baffled to not find a duplicate() method for a footage item… I was able to work around this using menu execution and a somewhat roundabout UID generation system.
Notice all the calls to select and deselect layers. You would also want to store your initial selection prior to executing a function like this.

pseudocode below. I wouldn’t call it pretty, but it works.


function duplicateFootageItem( item )
{
setAllProjectSelected(false);
item.selected = true;
originalName = item.name;
genName = generateRandomUid(10);
item.name = genName;
executeMenuCommand("Duplicate");
item.name = originalName;
dupedItem = findItemByName( genName + " 2"); //so cool
dupedItem.name = originalName + "_24fps"; // or whatever
return item;
}




Original credit for execute menu command comes from Chris Hatton but I can’t find the original post now except in cached form.

Feel free to post corrections and questions below. It might take me a couple of days to approve your comment, this blog is already spamtacular.


About this entry