function to select comps weirdness ???

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Posts: 9
Joined: December 14th, 2010, 9:13 pm


I wrote a function a while back to return an array of selected comps, either the frontmost comp timeline or the comps in the Project Panel if it is front most. The idea is that if the user was viewing a comp's Timeline (or viewer window) it would only return an array with ONLY that single comp, but if the user was looking at the Project Panel and had selected multiple comps there the function would return ALL those selected comps. It works a treat.

But... I've just noticed a weird behaviour which I can't for the life of me work out. If a project is opened fresh and I go straight to the Project Panel and select 2 or more comp items and run my script the function sees the Comp timeline panel (or the viewer) which is in the background as being the active Item and only returns that single comp. If I then bring the comp Timeline to the front momentarily and then go back to the Project Panel and select one or more comp items then the function works as expected. It is only this first time behaviour that is odd.

to be honest I find the whole task of determining which panel the user is currently interacting with quite confusing...

Any ideas as to why this is happening very greatly appreciated !

heres's the code

Code: Select all

var selComps = selectComps();

function selectComps(){     //returns an array of the selected comps using either the front most timeline or any comps selected in the project panel if it is front most

    var activeItem = app.project.activeItem;
    var projectSelection = app.project.selection;
    var selComps = [];

    if(activeItem != null){                         //use front most timeline
        if(activeItem.layers && app.activeViewer.type != ViewerType.VIEWER_FOOTAGE){
            selComps[0] = activeItem;
    else if(activeItem == null){                // use project selection instead and check for comps
            if(projectSelection[i].typeName== "Composition"){
    return selComps
Post Reply