FORUMS: list search recent posts

Sound layer names to text layers script

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Andreas Karlsson
Sound layer names to text layers script
on May 17, 2011 at 7:55:33 pm


Not an expression but a script question. I'm trying to get a script
to go through all layers in my selected comp, and create text layers with the corresponding name of the layers with active audio.

I have run into some problems. The for loop seems to work well, but when adding the actual text layers, it adds the correct number of layers, but stops on the first layer name. Also, right now it disregards audio layers or not.

In the end I would like to position these text layers in the correct/corresponding position in the timeline. But I can't figure out this first problem.

Quite new to this. Any ideas would be welcome. Thanks!


// undo group

app.beginUndoGroup("Sound layers to text layers");

var curItem = app.project.activeItem;

// check if comp is selected
if (curItem == null || !(curItem instanceof CompItem)){

// if no comp selected, display an alert
alert("Select a comp");

} else {

var totalLayers = curItem.numLayers;

// otherwise, loop through each layer in the selected comp
for (var b = 1; b &lt;= totalLayers; ++b){

// defines the layer in the loop we're currently looking at
var curLayer = curItem.layer(b);

// check if that layer is a audio layer
if (curLayer instanceof AVLayer){
if (curLayer.audioActive); {

// print layer name

var myAudiolayer = curItem.layers.addText (curItem.layer(b).name);

// position printed layers"Position").setValue([100, 20*b]);






Return to posts index

Dan Ebberts
Re: Sound layer names to text layers script
on May 17, 2011 at 8:35:29 pm

A couple of things jump out at me.

I would avoid adding layers in a loop that depends on numLayers and each layer's index, because any layer you add goes in at the top of the stack and will probably mess everything up. I think I would save all the names of layers with audio into an array and then have a second loop that creates the text layers from the name array.

I think I'd try this for the audio layer test:

(curLayer instanceof AVLayer && curLayer.hasAudio && curLayer.audioEnabled)


Return to posts index

Andreas Karlsson
Re: Sound layer names to text layers script
on May 18, 2011 at 2:04:00 pm

Thank you Dan! That solved the audio for me.

With some help I got it to work:

var proj = app.project;

// undo group
var undoStr = "Sound layers to text layers";

if (proj){
var myComp = app.project.activeItem;

if (myComp != null && (myComp instanceof CompItem)){

var myLayers = myComp.selectedLayers;
var saveIn = 0;
var saveOut = 0;

// Run through all selected layers
for (i=0; i &lt;= myLayers.length-1; i++){

var currentLayer = myLayers[i];
var saveIn = (currentLayer.stretch &lt; 0) ? currentLayer.outPoint : currentLayer.inPoint;
var saveOut = (currentLayer.stretch &lt; 0) ? currentLayer.inPoint : currentLayer.outPoint;

// Check for enabled audio
if (currentLayer instanceof AVLayer && currentLayer.hasAudio && currentLayer.audioEnabled){

// Create tex layer for each selected layer with audio enabled
var newTextLayer = myComp.layers.addText(myLayers[i].name);"Position").setValue([100, 15*i+30]);
newTextLayer.inPoint = saveIn
newTextLayer.outPoint = saveOut;


} else {
alert("Select all layers in the comp and then run the script again.");

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved