• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

How to Get the Active Comp

Community Expert ,
Jun 02, 2017 Jun 02, 2017

Copy link to clipboard

Copied

Does anyone know of a way to consistently access the active Comp? I'm currently using app.project.activeItem, however that only works if the last thing you selected was the comp or timeline. If you have a footage item selected in your project panel, for example, then I don't see a way to access the active Comp. Any thoughts are appreciated, thanks!

TOPICS
Scripting

Views

6.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 16, 2017 Jun 16, 2017

Copy link to clipboard

Copied

Hi Justin,

This looks like a question for the AE Scripting forum. You'll probably have more luck finding an answer to this over there as this is for the C++ SDK.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 22, 2017 Jun 22, 2017

Copy link to clipboard

Copied

justin2taylor  wrote

... If you have a footage item selected in your project panel, for example, then I don't see a way to access the active Comp....

If you have a footage item selected in your project panel, then I don't think you have an active comp.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 23, 2017 Jun 23, 2017

Copy link to clipboard

Copied

Mike is right. There are some new methods in scripting now...   .openInViewer()  and  the added viewer object, that would allow you more control. It is a scripting job.

Viewer object — After Effects Scripting Guide

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2017 Sep 13, 2017

Copy link to clipboard

Copied

Came back to this same issue after a few months and made this workaround:

app.activeViewer.setActive();

var activeComp = app.project.activeItem;

Basically setActive() will ensure that the project has an activeItem, and that that activeItem is not what is selected in the Project Panel, but in the Composition Panel.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

This isn't necessarily true, because you might have footage/layer in the viewer.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

Tomas, that's a good point, this method doesn't work if you have the Footage Panel or a Layer Panel in focus instead of the Composition panel. It's the best solution I can find, but if you know of a better method let me know. Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 14, 2017 Sep 14, 2017

Copy link to clipboard

Copied

Nope, nothing better out there.

I had your solution in mind, but didn't want to propose it here, as it's not 100% accurate.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 15, 2017 Sep 15, 2017

Copy link to clipboard

Copied

This is what i've been using for some time now, it works ok but is much circonvoluted.

It would definitely help a lot if the Viewer object had an attribute telling what that viewer is actually showing.

In this snippet, setActive is called only if necessary (to prevent the graphic focus ring to show up every time - annoying) and only if the active viewer is of type "COMPOSITION" (other types considered ambiguous).

If called twice in a row, it is most likely that the second time it will return a comp, even if the first time it returned null (because of the use of setActive).

function activateCompViewer(){

    // setActive is supposed (guide) to return a Boolean, but in practice it returns nothing, therefore this doesnt work:

    // return app.activeViewer && app.activeViewer.type===ViewerType.VIEWER_COMPOSITION && app.activeViewer.setActive();

  

    var A = (app.activeViewer && app.activeViewer.type===ViewerType.VIEWER_COMPOSITION);

    if (A) app.activeViewer.setActive();

    return A;

    };

function getActiveComp(){

  

    var comp;                                // the returned quantity

    var X = app.project.activeItem;    // the initial activeItem

    var selComp = app.project.selection.length ===1 && app.project.selection[0].typeName === "Composition" ? app.project.selection[0] : null; // the unique selected comp, or null

    var temp;

  

    if (X instanceof CompItem){

        if (selComp === null){

            comp = X;

            }

        else if (selComp !== X){

            comp = null; // ambiguity : the timeline panel is active, X is the front comp, but another comp is selected

            }

        else{

            // X and selComp coincide

            X.selected = false;

            temp = app.project.activeItem;

            X.selected = true;

          

            if (temp === null){

                // the project panel is active and the active item was initially a selected comp

                // if that comp is already opened in a viewer and is the front comp, return the comp, else : ambiguity

                comp = (activateCompViewer() && app.project.activeItem === X) ? X : null;

                }

            else{

                // deselecting the comp didnt change the activeItem : the timeline panel is active, and the active item was the front comp, that happened to be also selected.

                comp = X;

                };

            };

        }

    else{

        comp = activateCompViewer() ? app.project.activeItem : null;

        };

    return comp;

    };

var comp = getActiveComp();

alert(comp && comp.name);

Xavier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 18, 2023 Aug 18, 2023

Copy link to clipboard

Copied

LATEST

I'm late to the party, but wanted to add this method to the string. If you want to see if the activeItem is in the Project panel or in the Composition panel, I found this works (mostly):

 

let comp = app.project.activeItem;
// if the viewer is the comp viewer and isn't active
if (app.activeViewer.type == ViewerType.VIEWER_COMPOSITION && app.activeViewer.active == false){
    // make active
    app.activeViewer.setActive();
    // if the new activeItem isn't the original activeItem, then it's the project panel
    if (app.project.activeItem != comp){
        alert("Project panel is active.")
    }
    else {
        alert("Composition panel is active, or might as well be.")
    }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines