Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions app.executeCommand Question

  • app.executeCommand Question

    Posted by James Ronan on May 30, 2017 at 11:35 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

    James Ronan replied 8 years, 11 months ago 2 Members · 2 Replies
  • 2 Replies
  • Xavier Gomez

    May 30, 2017 at 12:59 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

  • James Ronan

    May 31, 2017 at 7:04 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy