ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

app.executeCommand Question

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
James Ronan
app.executeCommand Question
on May 30, 2017 at 11:35:27 am

Hey All!

I'm trying to use the app.executeCommand(); function to a specific layer in my array.

The problem I'm having is that it is executing the command across all layers, and I only want it for 2nd layer selected for example.

I've tried this but no luck:

var myLayer = app.project.activeItem.selectedLayers;

myLayer[1].executeCommand(10310);
myLayer[1].executeCommand(20);


Thanks for any help!

J


Return to posts index

Xavier Gomez
Re: app.executeCommand Question
on May 30, 2017 at 12:59:58 pm

You'll probably have to store the layer selection, deselect all layers except the one you want, use the command, and eventually reselect.

Xavier


Return to posts index

James Ronan
Re: app.executeCommand Question
on May 31, 2017 at 7:04:17 pm

Thanks a lot Xavier! That's exactly what I did.

There is probably a better way, but this is what I got working:

//Selects Layers
var myLayer = app.project.activeItem.selectedLayers;
var myLayerIndex = new Array();

//Stores selected Layers in Array
for (i = 0; i < myLayer.length; i++) {
myLayerIndex.push(myLayer[i].index)
}

//Selects Layers in comp
var selLayers = app.project.activeItem.layers;
//Loops through deselecting them
for (var j = 1; j <= selLayers.length; j++) {
selLayers[j].selected = false;
}

//Selects targer layer from stored selection
var targetLayer = app.project.activeItem.layer(myLayerIndex[1]);

targetLayer.selected = true;

//Applies command to selected layer
app.executeCommand(10310);
app.executeCommand(20);

//updates targetLayer variable is now the newly created layer.
targetLayer = app.project.activeItem.layer(targetLayer.index - 1);

//mattedLayer is original second selected layer
var mattedLayer = app.project.activeItem.layer(myLayerIndex[0] + 1);


Thanks for your help!

James


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]