Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions is it possible in a script to target a specific comp layer without having that comp selected in the project window ?

  • is it possible in a script to target a specific comp layer without having that comp selected in the project window ?

    Posted by Dirk De jong on October 15, 2017 at 6:43 pm

    I’m new to AE scripting, but I’m thinking the answer to my question in the subject line is “no.” and seeking confirmation or denial…

    It seems like there is no obvious way (in a script) to directly target the layer that is selected in the timeline tab that currently has focus (without requiring a user to select the comp in the project window)… like you can when applying an effect from the Effect menu (but I could be missing something). It seems like there is an activeViewer attribute but no activeTimeline attribute (which is perhaps part of what it would require)… If there is a way I suspect people on this forum would know. Thanks.

    Dirk De jong replied 8 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Xavier Gomez

    October 15, 2017 at 9:57 pm

    The After Effects scripting guide has a very loosy description of app.project.activeItem.
    If you follow it, you might think it is only determined by the panel selection, but it’s not.

    It seems to be determined in this order:

    if the Project Panel is active, then it is the unique selected item in that Panel, or null.
    if the Project Panel is not active, then it is the front comp in the Timeline Panel if any, or null again.

    (paradoxally, viewers dont play a role, you can have all viewers closed and no project selection, and still have a comp “active”: the one in front in the timeline panel).

    So you can do this:

    var X = app.project.activeItem;
    if (X instanceof CompItem && !X.selected){
    // X is the comp in front in the timeline
    }
    else{
    // stuck
    };

    If you have CS6 or later, you can do this prior to querying activeItem:

    if (app.activeViewer!=null && (app.activeViewer.type==ViewerType.VIEWER_COMPOSITION)){
    app.activeViewer.setActive();
    // at this stage, app.project.activeItem is necessarily the front comp in the timeline panel
    var comp = app.project.activeItem;
    var layers = comp.selectedLayers;
    }
    else{
    // ask to activate a comp
    };

    Xavier

  • Dirk De jong

    October 16, 2017 at 12:17 pm

    Thanks very much for the quick reply and useful suggestions. I’ll give these things a try.

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